1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use setting_tracker::Setting;
use std::rc::Rc;

#[derive(Default, Debug)]
struct Settings {
    str: Setting<String>,
}

fn main() {
    let mut settings = Settings::default();
    let s = Rc::new("abc".to_string());
    {
        let mut ss = s.to_string();
        settings.str.cb(move |o, n| {
            println!("{:?} -> {:?}", o, n);
            ss.push_str("...");
            println!("{:?} from closure", ss);
        });
    }
    println!("{}", s);
    settings.str.set("new".to_string());
    println!("{:?}", settings);
}

/*
Output:
    abc
    "" -> "new"
    "abc..." from closure
    Settings { str: "new" }
 */