Struct cvar::Property
[−]
[src]
pub struct Property<N, D, T, V, F> where
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
F: OnChange<T>, { /* fields omitted */ }
Property instance.
The N
ame and D
escription types allow abstracting over &'static str
, &'a str
and String
. This supports dynamic cvars while only paying for what you need.
The V
ariable type holds a value of the underlying T
ype with interior mutability.
F
is the callable type called when the value is changed.
Methods
impl<N, D, T, V> Property<N, D, T, V, Pass> where
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
[src]
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
fn new<I>(name: N, desc: D, var: V, def: I) -> Property<N, D, T, V, Pass> where
I: Into<T>,
I: Into<T>,
Creates a new Property
.
Given a name, description, variable and default.
// The underlying data wrapped in a `Cell`. use std::cell::Cell; let var = Cell::new(13); // The variable wrapped in a `Property`. use cvar::{Property, IProperty}; let prop = Property::new("prop", "property description", &var, 42); assert_eq!(prop.get(), "13"); prop.reset(); assert_eq!(var.get(), 42);
impl<N, D, T, V> Property<N, D, T, V, Pass> where
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
[src]
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
fn change<F>(self, change: F) -> Property<N, D, T, V, F> where
F: Fn(&T, T) -> BoxResult<T>,
F: Fn(&T, T) -> BoxResult<T>,
Creates a new Property
with change callback.
Called when a new value is assigned to the property through the set
and reset
methods.
It does not monitor the V
older for changes.
The default value must always validate successfully or reset
will panic.
Trait Implementations
impl<N, D, T, V, F> INode for Property<N, D, T, V, F> where
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
F: OnChange<T>,
[src]
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
F: OnChange<T>,
fn name(&self) -> &str
Returns the node name.
fn description(&self) -> &str
Returns the node description.
impl<N, D, T, V, F> IProperty for Property<N, D, T, V, F> where
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
F: OnChange<T>,
[src]
N: Borrow<str>,
D: Borrow<str>,
T: Value,
V: Variable<T>,
F: OnChange<T>,
fn get(&self) -> String
Gets the value as a string.
fn set(&self, val: &str) -> Result<(), InnerError>
Sets the value. Read more
fn reset(&self)
Resets the value to its default.
fn default(&self) -> String
Gets the default value as a string.
fn state(&self) -> PropState
Returns the state of the property.