Function cvar::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
18
19
20
21
	fn visit(&mut self, f: &mut dyn FnMut(&mut dyn cvar::INode)) {
		f(&mut cvar::Property("number", &mut self.number, &42));
		f(&mut cvar::Property("text", &mut self.text, &String::new()));
		f(&mut cvar::Action("poke!", |args, _writer| self.poke(args)));
	}
More examples
Hide additional examples
examples/nesting-techniques.rs (line 28)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
	fn visit(&mut self, f: &mut dyn FnMut(&mut dyn cvar::INode)) {
		f(&mut cvar::Action("int", |args, writer| self.before_int_changed(args, writer)));
		f(&mut cvar::Property("int", &mut self.int, &0));
		f(&mut cvar::Property("float", &mut self.float, &0.0));
		f(&mut cvar::Action("float", |args, writer| self.after_float_changed(args, writer)));
		f(&mut cvar::Property("string", &mut self.string, &String::new()));
	}
}

// Demonstrate how to create pseudo hierarchy allowing to inject nodes in a deeper nested namespace
// It is not possible to inject a node in a parent, this would also clash with Rust's borrowing rules
#[derive(Default)]
struct Nested {
	boolean: bool,
	foo: Foo,
}

impl cvar::IVisit for Nested {
	fn visit(&mut self, f: &mut dyn FnMut(&mut dyn cvar::INode)) {
		f(&mut cvar::Property("foo.bool", &mut self.boolean, &false));
		f(&mut cvar::List("foo", &mut self.foo));
	}