Guest User

Untitled

a guest
Feb 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 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. let mut main_menu = BTreeMap::new();
  12. // how to reference fn show_help() in line below??
  13. main_menu.insert(
  14. "h",
  15. MenuItem {
  16. name: "help",
  17. description: "Show help.",
  18. f: || { /* do things */ },
  19. },
  20. );
  21. main_menu.insert(
  22. "q",
  23. MenuItem {
  24. name: "quit",
  25. description: "Quit the program.",
  26. f: || {},
  27. },
  28. );
  29.  
  30. //dbg!(main_menu);
  31.  
  32. show_menu(main);
  33. }
  34.  
  35. fn menu() {
  36. // show menu in a loop until a break condition is satisfied...
  37. }
  38.  
  39. fn show_help() {
  40. println!("You appear to need help.");
  41. }
Add Comment
Please, Sign In to add comment