diff options
Diffstat (limited to 'src/callback.rs')
-rw-r--r-- | src/callback.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/callback.rs b/src/callback.rs new file mode 100644 index 0000000..c62ebf8 --- /dev/null +++ b/src/callback.rs @@ -0,0 +1,15 @@ +pub struct Callback<A: Sized + Send> { + items: Vec<fn(A)> +} + +impl<A: Sized + Clone + Send> Callback<A> { + pub fn new() -> Callback<A> { + Callback { items: Vec::new() } + } + pub fn register(&mut self, f: &fn(A)) { + self.items.push(*f) + } + pub fn fire(&self, v: &A) { + for _ in self.items.iter().map(|&c| c(v.clone())) {} + } +} |