Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let hello = Some("hello");
- let _switcheroo = hello.map(str::to_string); //ok
- let hello = Some("hello".to_string());
- let _switcheroo = hello.map(String::as_str); //not ok
- }
- error[E0631]: type mismatch in function arguments
- --> src/main.rs:6:29
- |
- 6 | let _switcheroo = hello.map(String::as_str);
- | ^^^
- | |
- | expected signature of `fn(std::string::String) -> _`
- | found signature of `for<'r> fn(&'r std::string::String) -> _`
- error: aborting due to previous error
- let hello = Some("hello".to_string());
- let _switcheroo = hello.as_ref().map(String::as_str); //ok
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement