Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 877 Bytes

README.md

File metadata and controls

31 lines (23 loc) · 877 Bytes

observer-rs

Build Status Crates.io version

Implementation of the observer software design pattern (also known as event emitter) for rust.

See the documentation for details.

struct Model {
    counter: usize,
}

impl Model {
        fn increment(&mut self) {
            self.counter += 1;
        }
}

let model = Model { counter: 42 };

// create a subject that can be observed
let mut subject = Subject::new(model);
// add a function that is informed about changes
subject.register(|v: &mut Model| println!("new counter value: {}", v.counter));

subject.get_mut_notify().increment();