Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- type CreateBox = fn() -> i32;
- fn frontier_fn() -> i32 {
- 1
- }
- fn homestead_fn() -> i32 {
- 2
- }
- fn main() {
- let patch_opts: HashMap<&str, CreateBox> =
- [("frontier", frontier_fn as CreateBox), ("homestead", homestead_fn)]
- .iter()
- .cloned()
- .collect();
- let opt = "frontier";
- match patch_opts.get(&opt) {
- Some(patch_fn) => println!("Result: {}", patch_fn()),
- None => println!("Option {} not found", opt),
- }
- }
Add Comment
Please, Sign In to add comment