Guest User

Untitled

a guest
Feb 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. use std::collections::BTreeMap;
  2.  
  3. #[derive(Debug)]
  4. struct MenuItem<F: FnOnce()> {
  5. name: &'static str,
  6. description: &'static str,
  7. f: F,
  8. }
  9.  
  10. fn main() {
  11.  
  12. let mut main_menu = BTreeMap::new();
  13. // how to reference fn show_help() in line below??
  14. main_menu.insert("h", MenuItem { name: "help", description: "Show help."}, f: || { /* do things */ });
  15. main_menu.insert("q", MenuItem { name: "quit", description: "Quit the program.", f: || { }});
  16.  
  17. //dbg!(main_menu);
  18.  
  19. show_menu(main);
  20. }
  21.  
  22. fn menu() {
  23. // show menu in a loop until a break condition is satisfied...
  24. }
  25.  
  26. fn show_help() {
  27. println!("You appear to need help.");
  28. }
Add Comment
Please, Sign In to add comment