pub struct DataComponentMap {
map: FxHashMap<Identifier, ComponentData>,
}Expand description
Storage for component values.
Maps component keys to their values. Used on items to store their data components.
Fields§
§map: FxHashMap<Identifier, ComponentData>Implementations§
Source§impl DataComponentMap
impl DataComponentMap
pub fn new() -> Self
Sourcepub fn common_item_components() -> Self
pub fn common_item_components() -> Self
Creates a map with common item components pre-populated.
Sourcepub fn builder_set<T: Component>(
self,
component: DataComponentType<T>,
value: Option<T>,
) -> Self
pub fn builder_set<T: Component>( self, component: DataComponentType<T>, value: Option<T>, ) -> Self
Sets a component value (builder pattern).
Sourcepub fn set<T: Component>(
&mut self,
component: DataComponentType<T>,
value: Option<T>,
)
pub fn set<T: Component>( &mut self, component: DataComponentType<T>, value: Option<T>, )
Sets a component value, or removes it if None.
Sourcepub fn get<T: Component>(&self, component: DataComponentType<T>) -> Option<T>
pub fn get<T: Component>(&self, component: DataComponentType<T>) -> Option<T>
Gets a component value by type.
Sourcepub fn get_ref<T: Component>(
&self,
component: DataComponentType<T>,
) -> Option<&T>
pub fn get_ref<T: Component>( &self, component: DataComponentType<T>, ) -> Option<&T>
Gets a reference to a component value.
Sourcepub fn has<T>(&self, component: DataComponentType<T>) -> bool
pub fn has<T>(&self, component: DataComponentType<T>) -> bool
Checks if a component is present.
Sourcepub fn keys(&self) -> impl Iterator<Item = &Identifier>
pub fn keys(&self) -> impl Iterator<Item = &Identifier>
Iterates over component keys.
Sourcepub fn get_raw(&self, key: &Identifier) -> Option<&ComponentData>
pub fn get_raw(&self, key: &Identifier) -> Option<&ComponentData>
Gets raw component data by key (for plugin use).
Sourcepub fn set_raw(&mut self, key: Identifier, data: ComponentData) -> bool
pub fn set_raw(&mut self, key: Identifier, data: ComponentData) -> bool
Sets raw component data (for plugin use).
Returns true if the data was set successfully, false if the data type
doesn’t match the registered component type (validation failed).
This prevents plugins from setting invalid types on vanilla components.
Sourcepub fn remove(&mut self, key: &Identifier) -> Option<ComponentData>
pub fn remove(&mut self, key: &Identifier) -> Option<ComponentData>
Removes a component by key.
Trait Implementations§
Source§impl Clone for DataComponentMap
impl Clone for DataComponentMap
Source§fn clone(&self) -> DataComponentMap
fn clone(&self) -> DataComponentMap
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DataComponentMap
impl Debug for DataComponentMap
Auto Trait Implementations§
impl Freeze for DataComponentMap
impl RefUnwindSafe for DataComponentMap
impl Send for DataComponentMap
impl Sync for DataComponentMap
impl Unpin for DataComponentMap
impl UnsafeUnpin for DataComponentMap
impl UnwindSafe for DataComponentMap
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