simple-observable 0.2.2

Simple observable pointer for mutable and immutable data
Documentation
  • Coverage
  • 16.67%
    1 out of 6 items documented0 out of 4 items with examples
  • Size
  • Source code size: 4.93 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • KurlykovDanila

Simple Observable

This simple library is made to notify you when your data changes

Adding a dependency: simple-observable = "0.2.2"

Changing observed values

use simple_observable::Observable;

fn main() {
    let a = 1;
    println!("Initial value: {}", a);
    let mut obs1 = Observable::new(a);
    obs1.add_listener(listener1);
    obs1.add_listener(listener2);
    obs1.add_listener(listener3);
    obs1.change(my_change_function);
}

fn my_change_function(num: &mut i32) {
    *num += 1;
}

fn listener1(num: &i32) {
    println!("(listener1) New value after change: {}", num);
}

fn listener2(num: &i32) {
    println!("(listener2) New value after change: {}", num);
}

fn listener3(num: &i32) {
    println!("(listener3) New value after change: {}", num);
}

Observable is a pointer that can be dereferenced and the data can be accessed directly. However, the data cannot be changed, but only read

It is important to understand that the Observable owns the data and the only way to change the data is to call the change() method.