Struct 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() -> ChangeSet<T>

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() -> ChangeSet<T>

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>(&mut self, iter: I)
where I: IntoIterator<Item = (Entity, T)>,

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>(iter: I) -> ChangeSet<T>
where I: IntoIterator<Item = (Entity, T)>,

Creates a value from an iterator. Read more
Source§

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

Source§

type Type = &'a T

Type of joined components.
Source§

type Value = &'a DenseVecStorage<T>

Type of joined storages.
Source§

type Mask = &'a BitSet

Type of joined bit mask.
Source§

unsafe fn open( self, ) -> (<&'a ChangeSet<T> as Join>::Mask, <&'a ChangeSet<T> as Join>::Value)

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

unsafe fn get( value: &mut <&'a ChangeSet<T> as Join>::Value, id: u32, ) -> <&'a ChangeSet<T> as Join>::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, T> Join for &'a mut ChangeSet<T>

Source§

type Type = &'a mut T

Type of joined components.
Source§

type Value = &'a mut DenseVecStorage<T>

Type of joined storages.
Source§

type Mask = &'a BitSet

Type of joined bit mask.
Source§

unsafe fn open( self, ) -> (<&'a mut ChangeSet<T> as Join>::Mask, <&'a mut ChangeSet<T> as Join>::Value)

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

unsafe fn get( v: &mut <&'a mut ChangeSet<T> as Join>::Value, id: u32, ) -> <&'a mut ChangeSet<T> as Join>::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<T> Join for ChangeSet<T>

Source§

type Type = T

Type of joined components.
Source§

type Value = DenseVecStorage<T>

Type of joined storages.
Source§

type Mask = BitSet

Type of joined bit mask.
Source§

unsafe fn open( self, ) -> (<ChangeSet<T> as Join>::Mask, <ChangeSet<T> as Join>::Value)

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

unsafe fn get( value: &mut <ChangeSet<T> as Join>::Value, id: u32, ) -> <ChangeSet<T> as Join>::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.

Auto Trait Implementations§

§

impl<T> Freeze for ChangeSet<T>

§

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

§

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 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> 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,