Expand description
Creating and extending objects with typed dynamic properties.
§Example
use dynprops::{Subject, Dynamic};
let subject = Subject::new();
let prop_a = subject.new_prop_const_init(5);
let prop_b = subject.new_prop_const_init("Foo");
let mut obj = Dynamic::new(&subject);
assert_eq!(obj[&prop_a], 5);
assert_eq!(obj[&prop_b], "Foo");
// Properties can be changed on a mutable object
obj[&prop_b] = "Foobar";
assert_eq!(obj[&prop_b], "Foobar");
// New properties can be introduced after an object is already created
let prop_c = subject.new_prop_default_init::<u32>();
assert_eq!(obj[&prop_c], 0u32);
// Properties can be initialized based on a function of other properties on the object
let prop_d = subject.new_prop_fn_init(|obj| obj[&prop_b].len());
assert_eq!(obj[&prop_d], 6);Structs§
- Const
Init - An
Initwhich initializes values by cloning a given value. - Default
Init - An
Initwhich initializes values usingDefault::default(). - Extended
- Extends a value of type
Twith properties defined in a particularSubject<T>. - FnInit
- An
Initwhich initializes values by executing a closure. - Property
- Identifies a property that is present on objects of the appropriate
Subject. - Subject
- Identifies a category of objects and a dynamic set of
Propertys that apply to those objects. New properties can be introduced into the subject at any time usingSubject::new_propand its derivatives. When accessing a property of an object, the subject of the property must match the subject of the object.
Traits§
Type Aliases§
- Const
Init Property - A shortcut for a
Propertythat is initialized by aConstInit. - Default
Init Property - A shortcut for a
Propertythat is initialized by aDefaultInit. - DynInit
- An
Initthat uses dynamic dispatch to defer to anotherInitat runtime. - DynInit
Property - A shortcut for a
Propertythat is initialized by aDynInit. Any property can be converted into aDynInitPropertyusingProperty::into_dyn_init. - Dynamic
- An object consisting entirely of dynamic properties defined in a particular
Subject. - FnInit
Property - A shortcut for a
Propertythat is initialized by aFnInit.