Function cvar::OwnedProp

source ·
pub fn OwnedProp<T>(name: String, variable: T, default: T) -> OwnedProp<T>
Examples found in repository?
examples/runtime-properties.rs (line 26)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	fn create(&mut self, args: &str, writer: &mut dyn cvar::IWrite) {
		// Crude argument parsing
		let args = args.trim();
		let first = args.split_ascii_whitespace().next().unwrap_or("");
		let args = args[first.len()..].trim_start();
		let second = args.split_ascii_whitespace().next().unwrap_or("");
		let third = args[second.len()..].trim_start();
		if first.len() == 0 {
			let _ = writeln!(writer, "Invalid arguments! expecting <type> <name> <value>");
			return;
		}
		match first {
			"string" => {
				let prop = cvar::OwnedProp(second.into(), String::from(third), String::from(third));
				self.props.push(Box::new(prop));
			},
			"int" => {
				let value: i32 = third.parse().unwrap();
				let prop = cvar::OwnedProp(second.into(), value, value);
				self.props.push(Box::new(prop));
			},
			"float" => {
				let value: f32 = third.parse().unwrap();
				let prop = cvar::OwnedProp(second.into(), value, value);
				self.props.push(Box::new(prop));
			},
			_ => {
				let _ = writeln!(writer, "Invalid type! supports string, int or float");
			},
		}
	}