Struct Storage

Source
pub struct Storage<C, D: UnprotectedStorage<C>, I> { /* private fields */ }
Expand description

A storage for components managed with specs_static::Id instead of Entity. This Storage behaves very similar to specsStorage.

§Registering

These component storages also have to be registered. This can be done using the WorldExt trait and its register_tile_comp method.

Implementations§

Source§

impl<C, D, I> Storage<C, D, I>
where C: Component, D: UnprotectedStorage<C>, I: Id,

Source

pub fn get(&self, id: I) -> Option<&C>

Tries to retrieve a component by its Id. This will only check whether a component is inserted or not, without doing any liveness checks for the id.

Examples found in repository?
examples/basic.rs (line 63)
62    fn run(&mut self, (tiles, materials): Self::SystemData) {
63        if let Some(mat) = materials.get(tiles.id(3, 4)) {
64            println!("The material at (3, 4) is {:?}.", mat);
65        }
66
67        let num_water: usize = (&*materials)
68            .join()
69            .map(|mat| match *mat {
70                Material::Water => 1,
71                _ => 0,
72            })
73            .sum();
74
75        println!("There are {} tiles with water.", num_water);
76    }
Source

pub fn get_mut(&mut self, id: I) -> Option<&mut C>

Tries to retrieve a component mutably by its Id. This will only check whether a component is inserted or not, without doing any liveness checks for the id.

Source

pub fn insert(&mut self, id: I, comp: C) -> Option<C>

Inserts comp at id. If there already was a value, it will be returned.

In contrast to entities, there are no invalid ids.

Examples found in repository?
examples/basic.rs (line 94)
79fn main() {
80    let mut d = DispatcherBuilder::new().with(Sys, "sys", &[]).build();
81    let mut w = World::new();
82
83    // Use method provided by `WorldExt`.
84    w.add_resource(Tiles::new(8, 8));
85    w.register_tile_comp::<Material, TileId>();
86
87    // Initialize
88
89    {
90        let tiles = w.read_resource::<Tiles>();
91        let mut materials: TileCompsMut<Material> = SystemData::fetch(&w.res);
92
93        for tile_id in tiles.iter_all() {
94            materials.insert(tile_id, Material::Dirt);
95        }
96
97        materials.insert(tiles.id(1, 5), Material::Grass);
98        materials.insert(tiles.id(2, 5), Material::Grass);
99        materials.insert(tiles.id(3, 4), Material::Water);
100        materials.insert(tiles.id(3, 7), Material::Water);
101    }
102
103    // ---
104
105    d.dispatch(&mut w.res);
106}
Source

pub fn remove(&mut self, id: I) -> Option<C>

Removes the component at id.

Trait Implementations§

Source§

impl<C, D, I> Default for Storage<C, D, I>

Source§

fn default() -> Self

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

impl<C, D, I> Drop for Storage<C, D, I>
where D: UnprotectedStorage<C>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, C, D, I> Join for &'a Storage<C, D, I>
where D: UnprotectedStorage<C>,

Source§

type Type = &'a C

Type of joined components.
Source§

type Value = &'a D

Type of joined storages.
Source§

type Mask = &'a BitSet

Type of joined bit mask.
Source§

unsafe fn open(self) -> (Self::Mask, Self::Value)

Open this join by returning the mask and the storages. Read more
Source§

unsafe fn get(value: &mut Self::Value, id: u32) -> Self::Type

Get a joined component value by a given index.
Source§

fn join(self) -> JoinIter<Self>
where Self: Sized,

Create a joined iterator over the contents.
Source§

fn maybe(self) -> MaybeJoin<Self>
where Self: Sized,

Returns a Join-able structure that yields all indices, returning None for all missing elements and Some(T) for found elements. Read more
Source§

fn is_unconstrained() -> bool

If this Join typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinIter/ParJoin to go through all indices which is usually not what is wanted and will kill performance.
Source§

impl<'a, C, D, I> Join for &'a mut Storage<C, D, I>
where D: UnprotectedStorage<C>,

Source§

type Type = &'a mut C

Type of joined components.
Source§

type Value = &'a mut D

Type of joined storages.
Source§

type Mask = &'a BitSet

Type of joined bit mask.
Source§

unsafe fn open(self) -> (Self::Mask, Self::Value)

Open this join by returning the mask and the storages. Read more
Source§

unsafe fn get(value: &mut Self::Value, id: u32) -> Self::Type

Get a joined component value by a given index.
Source§

fn join(self) -> JoinIter<Self>
where Self: Sized,

Create a joined iterator over the contents.
Source§

fn maybe(self) -> MaybeJoin<Self>
where Self: Sized,

Returns a Join-able structure that yields all indices, returning None for all missing elements and Some(T) for found elements. Read more
Source§

fn is_unconstrained() -> bool

If this Join typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinIter/ParJoin to go through all indices which is usually not what is wanted and will kill performance.
Source§

impl<C, D, I> Tracked for Storage<C, D, I>

Source§

fn channel(&self) -> &EventChannel<ComponentEvent>

Event channel tracking modified/inserted/removed components.
Source§

fn channel_mut(&mut self) -> &mut EventChannel<ComponentEvent>

Mutable event channel tracking modified/inserted/removed components.

Auto Trait Implementations§

§

impl<C, D, I> Freeze for Storage<C, D, I>
where D: Freeze,

§

impl<C, D, I> RefUnwindSafe for Storage<C, D, I>

§

impl<C, D, I> Send for Storage<C, D, I>
where D: Send, C: Send, I: Send,

§

impl<C, D, I> Sync for Storage<C, D, I>
where D: Sync, C: Sync, I: Sync,

§

impl<C, D, I> Unpin for Storage<C, D, I>
where D: Unpin, C: Unpin, I: Unpin,

§

impl<C, D, I> UnwindSafe for Storage<C, D, I>
where D: UnwindSafe, C: UnwindSafe, I: UnwindSafe,

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> Any for T
where T: Any,

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> TryDefault for T
where T: Default,

Source§

fn try_default() -> Result<T, String>

Tries to create the default.
Source§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
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<T> Erased for T

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> Resource for T
where T: Any + Send + Sync,