Open
Description
Given the following code:
fn main() {
let variable = Some(String::from("hello world"));
if variable == Some("hello world") {
println!("Hi!");
}
}
The current output is:
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
--> src/main.rs:3:25
|
3 | if variable == Some("hello world") {
| ---- ^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
| | |
| | expected struct `String`, found `&str`
| arguments to this enum variant are incorrect
|
note: tuple variant defined here
I think a better suggestion would be to use Option::as_deref()
or similar here, rather than unconditionally allocating a new string.