pub struct Property<T> { /* private fields */ }Expand description
Typed property handle. Wraps a PropertyKey with a phantom T so reads
and writes never stringify.
Construct with Self::new (global key) or Self::entity (entity-scoped
key). Round-trip through Self::get / Self::set against a
PropertyStore borrow.
use lumen_core::prelude::*;
let count: Property<i64> = Property::new("count");
let mut store = PropertyStore::default();
count.set(&mut store, 42);
assert_eq!(count.get(&store), Some(42));Implementations§
Source§impl<T> Property<T>
impl<T> Property<T>
Sourcepub fn new(name: impl Into<Arc<str>>) -> Self
pub fn new(name: impl Into<Arc<str>>) -> Self
Constructs a handle keyed on the global namespace (PropertyKey::Global).
Sourcepub fn entity(e: Entity, name: impl Into<Arc<str>>) -> Self
pub fn entity(e: Entity, name: impl Into<Arc<str>>) -> Self
Constructs a handle keyed on the entity-scoped namespace.
Sourcepub fn key(&self) -> &PropertyKey
pub fn key(&self) -> &PropertyKey
Borrows the underlying PropertyKey. Useful when the caller needs to
pass the key into raw PropertyStore APIs.
Sourcepub fn get(&self, store: &PropertyStore) -> Option<T>
pub fn get(&self, store: &PropertyStore) -> Option<T>
Reads the typed value from store. Returns None when the key is
absent. When the stored cell is a variant T doesn’t natively
represent, the conversion falls back to T’s Default-ish coercion
(matches the existing From<PropertyValue> for T semantics).
Sourcepub fn set(&self, store: &mut PropertyStore, value: T)
pub fn set(&self, store: &mut PropertyStore, value: T)
Writes value into the cell, bumping the cell’s generation and
appending to the dirty queue (subject to PropertyStore::freeze_notify).