Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let a = Some(String::from("Bomb"));
- println!("{}", match &a {
- //Some("Bomb") => "Boooomb!",
- // type mismatch error: expected String, got &str
- // How to make the line above work? The line below works as expected,
- // but it is too complicated.
- Some(inner) if inner == "Bomb" => "Boooomb!",
- // What is the type of `inner` here?
- // Seems that it depends on the type of value on the right (here the
- // "Bomb"):
- // When I try to change the right-side operand to be of different types
- // in order to let the compiler report the type of `inner`. Sometimes it
- // is "String" (e.g. for 8u8), other times it is "&String" (e.g. for
- // b"Bomb").
- // If it is the expected behaviour, could you please tell me what the
- // feature is called? I did not see explanations on it before.
- _ => "_"
- });
- }
Add Comment
Please, Sign In to add comment