Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. fn main() {
  2. let a = Some(String::from("Bomb"));
  3. println!("{}", match &a {
  4. //Some("Bomb") => "Boooomb!",
  5. // type mismatch error: expected String, got &str
  6. // How to make the line above work? The line below works as expected,
  7. // but it is too complicated.
  8.  
  9. Some(inner) if inner == "Bomb" => "Boooomb!",
  10. // What is the type of `inner` here?
  11. // Seems that it depends on the type of value on the right (here the
  12. // "Bomb"):
  13. // When I try to change the right-side operand to be of different types
  14. // in order to let the compiler report the type of `inner`. Sometimes it
  15. // is "String" (e.g. for 8u8), other times it is "&String" (e.g. for
  16. // b"Bomb").
  17. // If it is the expected behaviour, could you please tell me what the
  18. // feature is called? I did not see explanations on it before.
  19. _ => "_"
  20. });
  21. }
Add Comment
Please, Sign In to add comment