Type Definition specs::prelude::WriteStorage
[−]
[src]
type WriteStorage<'a, T> = Storage<'a, T, FetchMut<'a, MaskedStorage<T>>>;
A storage with read and write access.
Additionally to what ReadStorage
can do a storage with mutable access allows:
Aliasing
It is strictly disallowed to fetch both a ReadStorage
and a WriteStorage
of the same component.
Because Specs uses interior mutability for its resources, we can't check
this at compile time. If you try to do this, you will get a panic.
It is also disallowed to fetch multiple WriteStorage
s for the same
component.
Retrieve components mutably
This works just like Storage::get
, but returns a mutable reference:
let entity = world.create_entity() .with(Pos(2.0)) .build(); assert_eq!(pos_storage.get_mut(entity), Some(&mut Pos(2.0))); if let Some(pos) = pos_storage.get_mut(entity) { *pos = Pos(4.5); } assert_eq!(pos_storage.get(entity), Some(&Pos(4.5)));
Inserting and removing components
You can insert components using Storage::insert
and remove them
again with Storage::remove
.
let entity = world.create_entity() .with(Pos(0.1)) .build(); let res = pos_storage.insert(entity, Pos(4.0)); assert_eq!(res, InsertResult::Updated(Pos(0.1)));
There's also an Entry-API similar to the one provided by
std::collections::HashMap
.
Trait Implementations
impl<'a, T> SystemData<'a> for WriteStorage<'a, T> where
T: Component,
[src]
T: Component,
fn setup(res: &mut Resources)
[src]
Sets up Resources
for fetching this system data.
fn fetch(res: &'a Resources) -> Self
[src]
Creates a new resource bundle by fetching the required resources from the [Resources
] struct. Read more
fn reads() -> Vec<ResourceId>
[src]
A list of [ResourceId
]s the bundle needs read access to in order to build the target resource bundle. Read more
fn writes() -> Vec<ResourceId>
[src]
A list of [ResourceId
]s the bundle needs write access to in order to build the target resource bundle. Read more
impl<'a, T> GenericReadStorage for WriteStorage<'a, T> where
T: Component,
[src]
T: Component,
type Component = T
The component type of the storage
fn get(&self, entity: Entity) -> Option<&Self::Component>
[src]
Get immutable access to an Entity
s component
fn _private() -> Seal
[src]
Private function to seal the trait
impl<'a: 'b, 'b, T> GenericReadStorage for &'b WriteStorage<'a, T> where
T: Component,
[src]
T: Component,
type Component = T
The component type of the storage
fn get(&self, entity: Entity) -> Option<&Self::Component>
[src]
Get immutable access to an Entity
s component
fn _private() -> Seal
[src]
Private function to seal the trait
impl<'a, T> GenericWriteStorage for WriteStorage<'a, T> where
T: Component,
[src]
T: Component,
type Component = T
The component type of the storage
fn get_mut(&mut self, entity: Entity) -> Option<&mut Self::Component>
[src]
Get mutable access to an Entity
s component
fn insert(&mut self, entity: Entity, comp: Self::Component)
[src]
Insert a component for an Entity
fn remove(&mut self, entity: Entity)
[src]
Remove the component for an Entity
fn _private() -> Seal
[src]
Private function to seal the trait
impl<'a: 'b, 'b, T> GenericWriteStorage for &'b mut WriteStorage<'a, T> where
T: Component,
[src]
T: Component,
type Component = T
The component type of the storage
fn get_mut(&mut self, entity: Entity) -> Option<&mut Self::Component>
[src]
Get mutable access to an Entity
s component
fn insert(&mut self, entity: Entity, comp: Self::Component)
[src]
Insert a component for an Entity
fn remove(&mut self, entity: Entity)
[src]
Remove the component for an Entity
fn _private() -> Seal
[src]
Private function to seal the trait