pub fn insert(&mut self, e: Entity, mut v: T) -> InsertResult<T> {
        if self.entities.is_alive(e) {
            let id = e.id();
            if self.data.mask.contains(id) {
                // SAFETY: We checked the mask, so all invariants are met.
                std::mem::swap(&mut v, unsafe { self.data.inner.get_mut(id).deref_mut() });
                Ok(Some(v))
            } else {
                self.data.mask.add(id);
                // SAFETY: The mask was previously empty, so it is safe to insert.
                unsafe { self.data.inner.insert(id, v) };
                Ok(None)
            }
        } else {
            Err(Error::WrongGeneration(WrongGeneration {
                action: "insert component for entity",
                actual_gen: self.entities.entity(e.id()).gen(),
                entity: e,
            }))
        }
    }
/// Inserts new data for a given `Entity`.
/// Returns the result of the operation as a `InsertResult<T>`
///
/// If a component already existed for the given `Entity`, then it will
/// be overwritten with the new component. If it did overwrite, then the
/// result will contain `Some(T)` where `T` is the previous component.
Inserts new data for a given `Entity`.
Returns the result of the operation as a `InsertResult`

If a component already existed for the given `Entity`, then it will
be overwritten with the new component. If it did overwrite, then the
result will contain `Some(T)` where `T` is the previous component.
Inserts new data for a given ` Entity ` . Returns the result of the operation as a ` InsertResult ` If a component already existed for the given ` Entity ` then it will be overwritten with the new component . If it did overwrite then the result will contain ` Some ( T ) ` where ` T ` is the previous component .
pub fn insert(&mut self, e: Entity, mut v: T) -> InsertResult<T> {
        if self.entities.is_alive(e) {
            let id = e.id();
            if self.data.mask.contains(id) {
                // SAFETY: We checked the mask, so all invariants are met.
                std::mem::swap(&mut v, unsafe { self.data.inner.get_mut(id).deref_mut() });
                Ok(Some(v))
            } else {
                self.data.mask.add(id);
                // SAFETY: The mask was previously empty, so it is safe to insert.
                unsafe { self.data.inner.insert(id, v) };
                Ok(None)
            }
        } else {
            Err(Error::WrongGeneration(WrongGeneration {
                action: "insert component for entity",
                actual_gen: self.entities.entity(e.id()).gen(),
                entity: e,
            }))
        }
    }
pub fn insert ( & mut self , e : Entity , mut v : T ) -> InsertResult < T > { if self . entities . is_alive ( e ) { let id = e . id ( ) ; if self . data . mask . contains ( id ) { // SAFETY: We checked the mask, so all invariants are met. std :: mem :: swap ( & mut v , unsafe { self . data . inner . get_mut ( id ) . deref_mut ( ) } ) ; Ok ( Some ( v ) ) } else { self . data . mask . add ( id ) ; // SAFETY: The mask was previously empty, so it is safe to insert. unsafe { self . data . inner . insert ( id , v ) } ; Ok ( None ) } } else { Err ( Error :: WrongGeneration ( WrongGeneration { action : " " , actual_gen : self . entities . entity ( e . id ( ) ) . gen ( ) , entity : e , } ) ) } }
Inserts new data for a given `Entity`.
Inserts new data for a given ` Entity ` .
&mut self
e
Entity
v
T