You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::collections::hash_map::HashMap;fnmain(){letmut cmds:HashMap<String,Box<FnMut(&str)->()>> = HashMap::new();
cmds.insert("ping".to_string(),Box::new(|&mut: s| {println!("{}", s);}));//^ no type hintmatch cmds.get_mut("ping").map(|f| f("pong"));}
<anon>:6:37: 6:79 error: type mismatch: the type `closure[<anon>:6:46: 6:78]` implements the trait `core::ops::FnMut(_)`, but the trait `for<'r> core::ops::FnMut(&'r str)` is required (expected concrete lifetime, found bound lifetime parameter )
<anon>:6 cmds.insert("ping".to_string(), Box::new(|&mut: s| { println!("{}", s); }));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:6:37: 6:79 note: required for the cast to the object type `for<'r> core::ops::FnMut(&'r str)`
<anon>:6 cmds.insert("ping".to_string(), Box::new(|&mut: s| { println!("{}", s); }));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
It would be nice if the argument type could be inferred; having to hint every arg can be very verbose.
Possibly related to #20558, #20254, #19499, but this is a different error message.
The text was updated successfully, but these errors were encountered:
This works:
While this doesn't:
It would be nice if the argument type could be inferred; having to hint every arg can be very verbose.
Possibly related to #20558, #20254, #19499, but this is a different error message.
The text was updated successfully, but these errors were encountered: