pub struct Resources { /* private fields */ }Expand description
Container of engine resources — long-lived shared state that is principally data (with at most trivial accessors), not a service.
Admission criteria. A resource lives here when it is principally
data with trivial accessors (HashMaps, settings, caches), is shared
between several lanes / agents / data systems but has no rich business
API, and is long-lived (per-tick state belongs in
OutputDeck or LaneContext).
Many resources will internally use Arc<RwLock<…>> or Arc<Mutex<…>>
to support concurrent access. That is the resource’s responsibility,
not the container’s.
API mirrors the legacy ServiceRegistry (drop-in replacement).
Implementations§
Source§impl Resources
impl Resources
Sourcepub fn with_parent(parent: Arc<Resources>) -> Self
pub fn with_parent(parent: Arc<Resources>) -> Self
Creates a container that delegates lookups to parent when a key
is absent locally.
Sourcepub fn insert<T: Send + Sync + 'static>(&mut self, resource: T)
pub fn insert<T: Send + Sync + 'static>(&mut self, resource: T)
Inserts a resource, keyed by T’s TypeId.
Sourcepub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
Returns a borrow of the registered resource, walking the parent chain.
Sourcepub fn require<T: Send + Sync + 'static>(&self) -> &T
pub fn require<T: Send + Sync + 'static>(&self) -> &T
Returns a borrow of the registered resource, panicking if absent.