Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. use std::collections::HashMap;
  2. type CreateBox = fn() -> i32;
  3. fn frontier_fn() -> i32 {
  4. 1
  5. }
  6. fn homestead_fn() -> i32 {
  7. 2
  8. }
  9.  
  10. fn main() {
  11. let patch_opts: HashMap<&str, CreateBox> =
  12. [("frontier", frontier_fn as CreateBox), ("homestead", homestead_fn)]
  13. .iter()
  14. .cloned()
  15. .collect();
  16. let opt = "frontier";
  17. match patch_opts.get(&opt) {
  18. Some(patch_fn) => println!("Result: {}", patch_fn()),
  19. None => println!("Option {} not found", opt),
  20. }
  21. }
Add Comment
Please, Sign In to add comment