pub struct DataComponentType<T> {
pub(crate) key: Identifier,
ignore_swap_animation: bool,
_phantom: PhantomData<T>,
}Expand description
A typed handle for a data component.
This provides compile-time type safety when getting/setting components.
The actual storage uses keyed type erasure through ComponentData.
§Example
ⓘ
pub const DAMAGE: DataComponentType<Damage> =
DataComponentType::new(Identifier::vanilla_static("damage"));
// Type-safe access
let damage: Option<Damage> = components.get(DAMAGE);
components.set(DAMAGE, Damage(10));Steel declares component handles alongside their registered codecs; external callers cannot construct a handle for an existing key with a different type.
ⓘ
use steel_registry::data_components::DataComponentType;
use steel_utils::Identifier;
let _forged = DataComponentType::<bool>::new(Identifier::vanilla_static("max_damage"));Fields§
§key: Identifier§ignore_swap_animation: bool§_phantom: PhantomData<T>Implementations§
Source§impl<T> DataComponentType<T>
impl<T> DataComponentType<T>
pub(crate) const fn new(key: Identifier) -> Self
Sourcepub(crate) const fn new_ignoring_swap_animation(key: Identifier) -> Self
pub(crate) const fn new_ignoring_swap_animation(key: Identifier) -> Self
Creates a component type whose changes do not restart the held-item swap animation.
Sourcepub const fn ignore_swap_animation(&self) -> bool
pub const fn ignore_swap_animation(&self) -> bool
Returns whether this component is ignored when comparing held items for swap animation.
Sourcepub const fn key(&self) -> &Identifier
pub const fn key(&self) -> &Identifier
Returns this component type’s registry key.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DataComponentType<T>
impl<T> RefUnwindSafe for DataComponentType<T>where
T: RefUnwindSafe,
impl<T> Send for DataComponentType<T>where
T: Send,
impl<T> Sync for DataComponentType<T>where
T: Sync,
impl<T> Unpin for DataComponentType<T>where
T: Unpin,
impl<T> UnsafeUnpin for DataComponentType<T>
impl<T> UnwindSafe for DataComponentType<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreWraps this value in an
Arc<SyncMutex<>>