Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::BTreeMap;
- #[derive(Debug)]
- struct MenuItem<F: FnOnce()> {
- name: &'static str,
- description: &'static str,
- f: F,
- }
- fn main() {
- let mut main_menu = BTreeMap::new();
- // how to reference fn show_help() in line below??
- main_menu.insert("h", MenuItem { name: "help", description: "Show help."}, f: || { /* do things */ });
- main_menu.insert("q", MenuItem { name: "quit", description: "Quit the program.", f: || { }});
- //dbg!(main_menu);
- show_menu(main);
- }
- fn menu() {
- // show menu in a loop until a break condition is satisfied...
- }
- fn show_help() {
- println!("You appear to need help.");
- }
Add Comment
Please, Sign In to add comment