Guest User

Untitled

a guest
Jun 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. use std::sync::{Arc, Mutex};
  2.  
  3. struct Foo {
  4. listeners : Vec<Arc<Mutex<FnMut() + Send>>>
  5. }
  6.  
  7. impl Foo {
  8. fn new() -> Self {
  9. Foo {
  10. listeners: Vec::new()
  11. }
  12. }
  13. fn call_funcs(&mut self) {
  14. for f in &self.listeners {
  15. let mut f = f.lock().unwrap();
  16. let f = &mut *f;
  17. f();
  18. }
  19. }
  20. }
  21.  
  22. fn main() {
  23. let mut foo = Foo::new();
  24. foo.call_funcs();
  25.  
  26. println!("{:?}", 5);
  27. }
Add Comment
Please, Sign In to add comment