Macro v9::decl_property [−][src]
Declares a singleton property.
Example
decl_property! { /// Documentation can go here. /// This property is initialized via `Default`. #[derive(Clone)] // Derives also. pub MY_PROPERTY: ~i32 } decl_property! { // You can also initialize with an expression. Note the trailing semicolon. pub EXPLICIT_INIT: ~i32 = 237; } fn main() { let mut universe = Universe::new(); MY_PROPERTY::register(&mut universe); EXPLICIT_INIT::register(&mut universe); universe.kmap(|a: &mut MY_PROPERTY, b: &EXPLICIT_INIT| { **a += **b; }); }
impl doesn't use types inside crate
This is an error you’ll get if you try to make a property out of a type you don’t own.
You can get around this by putting a ~
in front of the type, as is done in the example here.
They’ll be slightly less pleasant to use… as you can see in the example here.