Struct specs::changeset::ChangeSet

source ·
pub struct ChangeSet<T> { /* private fields */ }
Expand description

Change set that can be collected from an iterator, and joined on for easy application to components.

Example


pub struct Health(i32);

impl Component for Health {
    type Storage = DenseVecStorage<Self>;
}


let a = world.create_entity().with(Health(100)).build();
let b = world.create_entity().with(Health(200)).build();

let changeset = [(a, 32), (b, 12), (b, 13)]
    .iter()
    .cloned()
    .collect::<ChangeSet<i32>>();
for (health, modifier) in (&mut world.write_storage::<Health>(), &changeset).join() {
    health.0 -= modifier;
}

Implementations§

source§

impl<T> ChangeSet<T>

source

pub fn new() -> Self

Create a new change set

source

pub fn add(&mut self, entity: Entity, value: T)where T: AddAssign,

Add a value to the change set. If the entity already have a value in the change set, the incoming value will be added to that.

source

pub fn clear(&mut self)

Clear the changeset

Trait Implementations§

source§

impl<T> Default for ChangeSet<T>

source§

fn default() -> Self

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

impl<T> Extend<(Entity, T)> for ChangeSet<T>where T: AddAssign,

source§

fn extend<I: IntoIterator<Item = (Entity, T)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> FromIterator<(Entity, T)> for ChangeSet<T>where T: AddAssign,

source§

fn from_iter<I: IntoIterator<Item = (Entity, T)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<'a, T> Join for &'a ChangeSet<T>

§

type Mask = &'a BitSet

Type of joined bit mask.
§

type Type = &'a T

Type of joined components.
§

type Value = &'a DenseVecStorage<T>

Type of joined storages.
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: Index) -> Self::Type

Get a joined component value by a given index. Read more
source§

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

Create a joined iterator over the contents.
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 to go through all indices which is usually not what is wanted and will kill performance.
source§

impl<'a, T> Join for &'a mut ChangeSet<T>

§

type Mask = &'a BitSet

Type of joined bit mask.
§

type Type = &'a mut T

Type of joined components.
§

type Value = SharedGetMutOnly<'a, T, DenseVecStorage<T>>

Type of joined storages.
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: Index) -> Self::Type

Get a joined component value by a given index. Read more
source§

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

Create a joined iterator over the contents.
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 to go through all indices which is usually not what is wanted and will kill performance.
source§

impl<T> Join for ChangeSet<T>

A Join implementation for ChangeSet that simply removes all the entries on a call to get.

§

type Mask = BitSet

Type of joined bit mask.
§

type Type = T

Type of joined components.
§

type Value = DenseVecStorage<T>

Type of joined storages.
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: Index) -> Self::Type

Get a joined component value by a given index. Read more
source§

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

Create a joined iterator over the contents.
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 to go through all indices which is usually not what is wanted and will kill performance.
source§

impl<'a, T> LendJoin for &'a ChangeSet<T>

§

type Mask = &'a BitSet

Type of joined bit mask.
§

type Value = &'a DenseVecStorage<T>

Type of joined storages.
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<'next>( value: &'next mut Self::Value, id: Index ) -> <Self as LendJoinඞType<'next>>::T

Get a joined component value by a given index. Read more
source§

fn lend_join(self) -> JoinLendIter<Self>where Self: Sized,

Create a joined lending iterator over the contents.
source§

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

Returns a structure that implements Join/LendJoin/MaybeJoin if the contained T does and 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 LendJoin typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinLendIter to go through all indices which is usually not what is wanted and will kill performance.
source§

impl<'a, T> LendJoin for &'a mut ChangeSet<T>

§

type Mask = &'a BitSet

Type of joined bit mask.
§

type Value = &'a mut DenseVecStorage<T>

Type of joined storages.
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<'next>( value: &'next mut Self::Value, id: Index ) -> <Self as LendJoinඞType<'next>>::T

Get a joined component value by a given index. Read more
source§

fn lend_join(self) -> JoinLendIter<Self>where Self: Sized,

Create a joined lending iterator over the contents.
source§

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

Returns a structure that implements Join/LendJoin/MaybeJoin if the contained T does and 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 LendJoin typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinLendIter to go through all indices which is usually not what is wanted and will kill performance.
source§

impl<T> LendJoin for ChangeSet<T>

A Join implementation for ChangeSet that simply removes all the entries on a call to get.

§

type Mask = BitSet

Type of joined bit mask.
§

type Value = DenseVecStorage<T>

Type of joined storages.
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<'next>( value: &'next mut Self::Value, id: Index ) -> <Self as LendJoinඞType<'next>>::T

Get a joined component value by a given index. Read more
source§

fn lend_join(self) -> JoinLendIter<Self>where Self: Sized,

Create a joined lending iterator over the contents.
source§

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

Returns a structure that implements Join/LendJoin/MaybeJoin if the contained T does and 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 LendJoin typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinLendIter to go through all indices which is usually not what is wanted and will kill performance.
source§

impl<'a, T> RepeatableLendGet for &'a ChangeSet<T>

source§

impl<'a, T> RepeatableLendGet for &'a mut ChangeSet<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ChangeSet<T>

§

impl<T> Send for ChangeSet<T>where T: Send,

§

impl<T> Sync for ChangeSet<T>where T: Sync,

§

impl<T> Unpin for ChangeSet<T>where T: Unpin,

§

impl<T> UnwindSafe for ChangeSet<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> TryDefault for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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> Event for Twhere T: Send + Sync + 'static,

source§

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