SHARE
TWEET

Untitled

a guest Jul 15th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::collections::HashMap;
  2.  
  3. fn main() {
  4.     let c: &'static str = "C";
  5.     let mut map: HashMap<&'static str, Box<FnOnce()>> = HashMap::new();
  6.     map.insert("A", Box::new(|| { println!("A") }));
  7.     map.insert("B", Box::new(test));
  8.     map.insert("C", Box::new(|| println!("{}", c)));
  9.  
  10.     map.remove("A").unwrap()();
  11.     map.remove("B").unwrap()();
  12.     map.remove("C").unwrap()();
  13. }
  14.  
  15. fn test() {
  16.     println!("B");
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top