Earlier quoted context omitted.
fn main() { let s1 = "Hello, world"; // &str let s2 = String::from("Hello, world"); // String assert_eq!(s1, s2); assert_eq!(s2, s1); } compiles just fine for me?
Okay, once again I try to find an example from my code, and once again it turns out that Rust makes it simple in the simple case, but the more complex cases are still confusing. If I change the test value Some("zh".to_string()) into Some("zh"), it points to that line and tells me: expected struct `std::string::String`, found &str Sure, it's a different situation because the value is wrapped in an Option. But if Strin…
String and &str can normally be compared because of Deref, that is, &String derefs to &str. Option, on the other hand, does not implement Deref, and so no coercion happens. Rust doesn't do a lot of coercions, but Deref is one of the bigger ones.
Back to the _actual_ topic at hand, I can see how this can be a pain point until you know the rules, though. :/