pub struct ResourceRegistry { /* private fields */ }Expand description
Per-World bidirectional map between Resource TypeId and the hidden
GlobalEntity carrying that resource as a single component.
Maintained on both sides:
- Sender (
HostWorldManager): inserted atinsert_resource::<R>(...)time, removed atremove_resource::<R>()time. - Receiver (
RemoteWorldManager): inserted when an incomingSpawnWithComponentscarries a component whose kind is registered inprotocol.resource_kinds. Removed on entity despawn.
Lookups are O(1) in both directions:
entity_for(TypeId)→ “where is the hidden entity for resource R?”type_for(GlobalEntity)→ “is this entity a resource, and which one?” (used to suppress the entity from user-visible scope/event streams).
Implementations§
Source§impl ResourceRegistry
impl ResourceRegistry
Sourcepub fn insert<R: 'static>(
&mut self,
entity: GlobalEntity,
) -> Result<(), ResourceAlreadyExists>
pub fn insert<R: 'static>( &mut self, entity: GlobalEntity, ) -> Result<(), ResourceAlreadyExists>
Insert a (TypeId, GlobalEntity) pair. Fails with
ResourceAlreadyExists if the TypeId is already registered (the
commands.replicate_resource API surface treats this as an error
per D14/risk-register).
Sourcepub fn insert_raw(
&mut self,
type_id: TypeId,
entity: GlobalEntity,
) -> Result<(), ResourceAlreadyExists>
pub fn insert_raw( &mut self, type_id: TypeId, entity: GlobalEntity, ) -> Result<(), ResourceAlreadyExists>
Receiver-side variant: insert by raw TypeId (the receiver derives
the TypeId from the incoming ComponentKind via the
ResourceKinds registration). Idempotent if the same pair is
already present (e.g. spawn-after-spawn replay), returns error
otherwise.
Sourcepub fn remove<R: 'static>(&mut self) -> Option<GlobalEntity>
pub fn remove<R: 'static>(&mut self) -> Option<GlobalEntity>
Remove a resource by type. Returns the removed entity if present.
Sourcepub fn remove_by_entity(&mut self, entity: &GlobalEntity) -> Option<TypeId>
pub fn remove_by_entity(&mut self, entity: &GlobalEntity) -> Option<TypeId>
Receiver-side: remove by entity (used when an incoming Despawn for a resource entity arrives).
Sourcepub fn entity_for<R: 'static>(&self) -> Option<GlobalEntity>
pub fn entity_for<R: 'static>(&self) -> Option<GlobalEntity>
O(1): “where is the hidden entity for resource R?”
Sourcepub fn entity_for_raw(&self, type_id: &TypeId) -> Option<GlobalEntity>
pub fn entity_for_raw(&self, type_id: &TypeId) -> Option<GlobalEntity>
O(1) raw-TypeId variant.
Sourcepub fn type_for(&self, entity: &GlobalEntity) -> Option<TypeId>
pub fn type_for(&self, entity: &GlobalEntity) -> Option<TypeId>
O(1): “is this entity a resource entity, and if so which type?”
Sourcepub fn is_resource_entity(&self, entity: &GlobalEntity) -> bool
pub fn is_resource_entity(&self, entity: &GlobalEntity) -> bool
O(1): “is this entity a resource entity?”
Sourcepub fn iter(&self) -> impl Iterator<Item = (&TypeId, &GlobalEntity)>
pub fn iter(&self) -> impl Iterator<Item = (&TypeId, &GlobalEntity)>
Iterate over all (TypeId, GlobalEntity) pairs. Used by the
scope resolver to auto-include resource entities in every user’s
scope.
Sourcepub fn entities(&self) -> impl Iterator<Item = &GlobalEntity>
pub fn entities(&self) -> impl Iterator<Item = &GlobalEntity>
Iterate over just the resource entities (for scope auto-inclusion).
Trait Implementations§
Source§impl Clone for ResourceRegistry
impl Clone for ResourceRegistry
Source§fn clone(&self) -> ResourceRegistry
fn clone(&self) -> ResourceRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more