Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::{Arc, Mutex};
- struct Foo {
- listeners : Vec<Arc<Mutex<FnMut() + Send>>>
- }
- impl Foo {
- fn new() -> Self {
- Foo {
- listeners: Vec::new()
- }
- }
- fn call_funcs(&mut self) {
- for f in &self.listeners {
- let mut f = f.lock().unwrap();
- let f = &mut *f;
- f();
- }
- }
- }
- fn main() {
- let mut foo = Foo::new();
- foo.call_funcs();
- println!("{:?}", 5);
- }
Add Comment
Please, Sign In to add comment