pub fn entry<'a>(&'a mut self, e: Entity) -> Result<StorageEntry<'a, 'e, T, D>, WrongGeneration>
    where
        'e: 'a,
    {
        if self.entities.is_alive(e) {
            unsafe {
                let entries = self.entries();
                // SAFETY: This is safe since we're not swapping out the mask or the values.
                let (_, mut value): (BitSetAll, _) = entries.open();
                // SAFETY: We did check the mask, because the mask is `BitSetAll` and every
                // index is part of it.
                Ok(Entries::get(&mut value, e.id()))
            }
        } else {
            let gen = self
                .entities
                .alloc
                .generation(e.id())
                .unwrap_or_else(Generation::one);
            Err(WrongGeneration {
                action: "attempting to get an entry to a storage",
                actual_gen: gen,
                entity: e,
            })
        }
    }
/// Returns an entry to the component associated to the entity.
///
/// Behaves somewhat similarly to `std::collections::HashMap`'s entry api.
///
/// ## Example
///
/// ```rust
/// # extern crate specs;
/// # use specs::prelude::*;
/// # struct Comp {
/// #    field: u32
/// # }
/// # impl Component for Comp {
/// #    type Storage = DenseVecStorage<Self>;
/// # }
/// # fn main() {
/// # let mut world = World::new();
/// # world.register::<Comp>();
/// # let entity = world.create_entity().build();
/// # let mut storage = world.write_storage::<Comp>();
/// if let Ok(entry) = storage.entry(entity) {
///     entry.or_insert(Comp { field: 55 });
/// }
/// # }
/// ```
Returns an entry to the component associated to the entity.
Behaves somewhat similarly to `std::collections::HashMap`'s entry api.
Returns an entry to the component associated to the entity . Behaves somewhat similarly to ` std :: collections :: HashMap ` ' s entry api .
pub fn entry<'a>(&'a mut self, e: Entity) -> Result<StorageEntry<'a, 'e, T, D>, WrongGeneration>
    where
        'e: 'a,
    {
        if self.entities.is_alive(e) {
            unsafe {
                let entries = self.entries();
                // SAFETY: This is safe since we're not swapping out the mask or the values.
                let (_, mut value): (BitSetAll, _) = entries.open();
                // SAFETY: We did check the mask, because the mask is `BitSetAll` and every
                // index is part of it.
                Ok(Entries::get(&mut value, e.id()))
            }
        } else {
            let gen = self
                .entities
                .alloc
                .generation(e.id())
                .unwrap_or_else(Generation::one);
            Err(WrongGeneration {
                action: "attempting to get an entry to a storage",
                actual_gen: gen,
                entity: e,
            })
        }
    }
pub fn entry < ' a > ( & ' a mut self , e : Entity ) -> Result < StorageEntry < ' a , ' e , T , D > , WrongGeneration > where ' e : ' a , { if self . entities . is_alive ( e ) { unsafe { let entries = self . entries ( ) ; // SAFETY: This is safe since we're not swapping out the mask or the values. let ( _ , mut value ) : ( BitSetAll , _ ) = entries . open ( ) ; // SAFETY: We did check the mask, because the mask is `BitSetAll` and every // index is part of it. Ok ( Entries :: get ( & mut value , e . id ( ) ) ) } } else { let gen = self . entities . alloc . generation ( e . id ( ) ) . unwrap_or_else ( Generation :: one ) ; Err ( WrongGeneration { action : " " , actual_gen : gen , entity : e , } ) } }
Returns an entry to the component associated to the entity.
Returns an entry to the component associated to the entity .
&'a mut self
e
Entity
example
None
extern crate specs;
None
use specs::prelude::*;
None
struct comp {
None
field: u32
None
}
None
impl component for comp {
None
type storage = densevecstorage<self>;
None
}
None
fn main() {
None
let mut world = world::new();
None
world.register::<comp>();
None
let entity = world.create_entity().build();
None
let mut storage = world.write_storage::<comp>();
if let Ok(entry) = storage.entry(entity) {
entry.or_insert(Comp { field: 55 });
}
if let Ok ( entry ) = storage . entry ( entity ) { entry . or_insert ( Comp { field : 55 } ) ; }
}
None