pub struct ResourceKinds { /* private fields */ }Expand description
Protocol-wide table marking which ComponentKinds are Replicated
Resources (vs ordinary components).
A Resource type R is registered via Protocol::add_resource::<R>(),
which:
- Calls
component_kinds.add_component::<R>()to allocate a normalComponentKind+ NetId forR. Resources reuse the component wire encoding 100% — they ARE components, just on a hidden singleton entity. - Records the resulting
ComponentKindin this table so the receiver side can recognize incomingSpawnWithComponentsmessages whose components are resources, and populate itsResourceRegistryaccordingly.
There is no wire representation of ResourceKinds itself — the table
is built identically on both sides from the same ProtocolPlugin
registration order, exactly like ComponentKinds.
Implementations§
Source§impl ResourceKinds
impl ResourceKinds
Sourcepub fn register<R: 'static>(&mut self, kind: ComponentKind)
pub fn register<R: 'static>(&mut self, kind: ComponentKind)
Register R as a resource kind. Idempotent: re-registering the
same type is a no-op (matches the add_component re-registration
semantics — the component table dedupes on TypeId).
R: 'static is the only bound — internal callers always have
the full Replicate bound, but this method only uses
TypeId::of::<R>() so we don’t impose more.
Sourcepub fn is_resource(&self, kind: &ComponentKind) -> bool
pub fn is_resource(&self, kind: &ComponentKind) -> bool
O(1) — is the given ComponentKind a registered resource?
Sourcepub fn kind_for<R: 'static>(&self) -> Option<ComponentKind>
pub fn kind_for<R: 'static>(&self) -> Option<ComponentKind>
Return the ComponentKind registered for R, or None if R
was never registered as a resource.
Implementation note: ComponentKind is TypeId-keyed
(shared/src/world/component/component_kinds.rs:53), so we
construct the kind from R’s TypeId and check membership.
Sourcepub fn iter(&self) -> impl Iterator<Item = &ComponentKind>
pub fn iter(&self) -> impl Iterator<Item = &ComponentKind>
Iterate over all registered resource kinds.
Trait Implementations§
Source§impl Clone for ResourceKinds
impl Clone for ResourceKinds
Source§fn clone(&self) -> ResourceKinds
fn clone(&self) -> ResourceKinds
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more