mikelodder7 / celes

Convenience rust crate for handling ISO 3661-1
Apache License 2.0
16 stars 5 forks source link

can't be used / imported on current rust 1.65 in edition 2021 on arm host (macos m1) #9

Open cguentherTUChemnitz opened 1 year ago

cguentherTUChemnitz commented 1 year ago

The version 1.0.6 is working fine, but all 2.x versions seem to be borked.

steps to reproduce:

cargo new --bin celes_test
cd celes_test
cargo add celes
cargo build

mainly endless the same error:

error[E0599]: no method named `to_lowercase` found for reference `&str` in the current scope
error output ```bash cargo build Compiling celes v2.4.0 error[E0599]: no method named `to_lowercase` found for reference `&str` in the current scope --> /Users/cguenther/.cargo/registry/src/github.com-1ecc6299db9ec823/celes-2.4.0/src/tables.rs:23:29 | 23 | match alias.to_lowercase().as_str() { | ^^^^^^^^^^^^ method not found in `&str` ... 201 | lookup!(SamoaTable, Samoa, "American Samoa", 1, "Samoa" => "samoa"); | ------------------------------------------------------------------- in this macro invocation | = note: this error originates in the macro `lookup` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no method named `join` found for array `[&'static str; 1]` in the current scope --> /Users/cguenther/.cargo/registry/src/github.com-1ecc6299db9ec823/celes-2.4.0/src/tables.rs:117:42 | 117 | write!(f, "[{}]", self.0.join(",")) | ^^^^ method not found in `[&'static str; 1]` ... 201 | lookup!(SamoaTable, Samoa, "American Samoa", 1, "Samoa" => "samoa"); | ------------------------------------------------------------------- in this macro invocation | = note: this error originates in the macro `lookup` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no method named `join` found for array `[&'static str; 1]` in the current scope --> /Users/cguenther/.cargo/registry/src/github.com-1ecc6299db9ec823/celes-2.4.0/src/tables.rs:123:66 | 123 | write!(f, "{} - [{}]", stringify!($name), self.0.join(",")) | ^^^^ method not found in `[&'static str; 1]` ... 201 | lookup!(SamoaTable, Samoa, "American Samoa", 1, "Samoa" => "samoa"); | ------------------------------------------------------------------- in this macro invocation | = note: this error originates in the macro `lookup` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no method named `to_lowercase` found for reference `&str` in the current scope --> /Users/cguenther/.cargo/registry/src/github.com-1ecc6299db9ec823/celes-2.4.0/src/tables.rs:23:29 | 23 | match alias.to_lowercase().as_str() { | ^^^^^^^^^^^^ method not found in `&str` ... 202 | lookup!(SaintHelenaTable, SaintHelena, "Ascension And Tristan Da Cunha Saint Helena", 2, "StHelena" => "sthelena", "SaintHelena" => "sainthelena... | -------------------------------------------------------------------------------------------------------------------------------------------------- in this macro invocation | = note: this error originates in the macro `lookup` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no method named `join` found for array `[&'static str; 2]` in the current scope --> /Users/cguenther/.cargo/registry/src/github.com-1ecc6299db9ec823/celes-2.4.0/src/tables.rs:117:42 | 117 | write!(f, "[{}]", self.0.join(",")) | ^^^^ method not found in `[&'static str; 2]` ... 202 | lookup!(SaintHelenaTable, SaintHelena, "Ascension And Tristan Da Cunha Saint Helena", 2, "StHelena" => "sthelena", "SaintHelena" => "sainthelena... | -------------------------------------------------------------------------------------------------------------------------------------------------- in this macro invocation | = note: this error originates in the macro `lookup` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no method named `join` found for array `[&'static str; 2]` in the current scope --> /Users/cguenther/.cargo/registry/src/github.com-1ecc6299db9ec823/celes-2.4.0/src/tables.rs:123:66 | 123 | write!(f, "{} - [{}]", stringify!($name), self.0.join(",")) | ^^^^ method not found in `[&'static str; 2]` ... ... // croppet to be able to submit the issue on github, which is capped to 65536 chars ```
Alvenix commented 1 year ago

I think the bug is because the crate is marked as #[no_std] while using methods like to_lowercase which require std as the need String type.

mikelodder7 commented 1 year ago

Yeah I've been trying to find a good solution to that with the heapless crate but haven't gotten a clean one yet

Alvenix commented 1 year ago

Yeah I've been trying to find a good solution to that with the heapless crate but haven't gotten a clean one yet

Perhaps not the cleanest, but maybe using eq_ignore_ascii_case with many if else statements instead of a match is good alternative.

https://doc.rust-lang.org/std/primitive.str.html#method.eq_ignore_ascii_case

mikelodder7 commented 1 year ago

Hmmm. If I run cargo test in the celes crate everything passes. I wonder if there's a dependency problem somewhere.

Alvenix commented 1 year ago

Hmmm. If I run cargo test in the celes crate everything passes. I wonder if there's a dependency problem somewhere.

Adding resolver = "2" to Cargo.toml stop the code of compiling with the same errors in this issue. Because dev-dependencies use serde_json which depend on std so without resolver = "2", it will consider std to be dependency of the crate. Alternatively changing serde_json to serde-json-core which doesn't depend on std also stop the code from compiling.