Property

Function Property 

Source
pub fn Property<'a, 'x, T>(
    name: &'a str,
    variable: &'x mut T,
    default: &'a T,
) -> Property<'a, 'x, T>
Examples found in repository?
examples/readme-example.rs (line 18)
17	fn visit(&mut self, f: &mut dyn FnMut(&mut dyn cvar::INode)) {
18		f(&mut cvar::Property("number", &mut self.number, &42));
19		f(&mut cvar::Property("text", &mut self.text, &String::new()));
20		f(&mut cvar::Action("poke!", |args, _writer| self.poke(args)));
21	}
More examples
Hide additional examples
examples/nesting-techniques.rs (line 28)
26	fn visit(&mut self, f: &mut dyn FnMut(&mut dyn cvar::INode)) {
27		f(&mut cvar::Action("int", |args, writer| self.before_int_changed(args, writer)));
28		f(&mut cvar::Property("int", &mut self.int, &0));
29		f(&mut cvar::Property("float", &mut self.float, &0.0));
30		f(&mut cvar::Action("float", |args, writer| self.after_float_changed(args, writer)));
31		f(&mut cvar::Property("string", &mut self.string, &String::new()));
32	}
33}
34
35// Demonstrate how to create pseudo hierarchy allowing to inject nodes in a deeper nested namespace
36// It is not possible to inject a node in a parent, this would also clash with Rust's borrowing rules
37#[derive(Default)]
38struct Nested {
39	boolean: bool,
40	foo: Foo,
41}
42
43impl cvar::IVisit for Nested {
44	fn visit(&mut self, f: &mut dyn FnMut(&mut dyn cvar::INode)) {
45		f(&mut cvar::Property("foo.bool", &mut self.boolean, &false));
46		f(&mut cvar::List("foo", &mut self.foo));
47	}