aboutsummaryrefslogtreecommitdiff
path: root/src/callback.rs
blob: c62ebf881fd981b6673e311811e6277a50ffce33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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())) {}
    }
}