Skip to main content

ResourceRegistry

Struct ResourceRegistry 

Source
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 at insert_resource::<R>(...) time, removed at remove_resource::<R>() time.
  • Receiver (RemoteWorldManager): inserted when an incoming SpawnWithComponents carries a component whose kind is registered in protocol.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

Source

pub fn new() -> Self

Creates an empty ResourceRegistry.

Source

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).

Source

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.

Source

pub fn remove<R: 'static>(&mut self) -> Option<GlobalEntity>

Remove a resource by type. Returns the removed entity if present.

Source

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).

Source

pub fn entity_for<R: 'static>(&self) -> Option<GlobalEntity>

O(1): “where is the hidden entity for resource R?”

Source

pub fn entity_for_raw(&self, type_id: &TypeId) -> Option<GlobalEntity>

O(1) raw-TypeId variant.

Source

pub fn type_for(&self, entity: &GlobalEntity) -> Option<TypeId>

O(1): “is this entity a resource entity, and if so which type?”

Source

pub fn is_resource_entity(&self, entity: &GlobalEntity) -> bool

O(1): “is this entity a resource entity?”

Source

pub fn len(&self) -> usize

Returns the number of registered resources.

Source

pub fn is_empty(&self) -> bool

Returns true if no resources have been registered.

Source

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.

Source

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

Source§

fn clone(&self) -> ResourceRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResourceRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResourceRegistry

Source§

fn default() -> ResourceRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V