Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. fn main() {
  2. let hello = Some("hello");
  3. let _switcheroo = hello.map(str::to_string); //ok
  4.  
  5. let hello = Some("hello".to_string());
  6. let _switcheroo = hello.map(String::as_str); //not ok
  7.  
  8. }
  9.  
  10. error[E0631]: type mismatch in function arguments
  11. --> src/main.rs:6:29
  12. |
  13. 6 | let _switcheroo = hello.map(String::as_str);
  14. | ^^^
  15. | |
  16. | expected signature of `fn(std::string::String) -> _`
  17. | found signature of `for<'r> fn(&'r std::string::String) -> _`
  18.  
  19. error: aborting due to previous error
  20.  
  21. let hello = Some("hello".to_string());
  22. let _switcheroo = hello.as_ref().map(String::as_str); //ok
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement