OccupiedComponentEntry

Struct OccupiedComponentEntry 

Source
pub struct OccupiedComponentEntry<'w, 'a, T: Component> { /* private fields */ }
Expand description

A view into an occupied entry in a EntityWorldMut. It is part of the OccupiedComponentEntry enum.

The contained entity must have the component type parameter if we have this struct.

Implementations§

Source§

impl<'w, 'a, T: Component> OccupiedComponentEntry<'w, 'a, T>

Source

pub fn get(&self) -> &T

Gets a reference to the component in the entry.

§Examples
#[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
struct Comp(u32);

let mut entity = world.spawn(Comp(5));

if let ComponentEntry::Occupied(o) = entity.entry::<Comp>() {
    assert_eq!(o.get().0, 5);
}
Source

pub fn insert(&mut self, component: T)

Replaces the component of the entry.

§Examples
#[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
struct Comp(u32);

let mut entity = world.spawn(Comp(5));

if let ComponentEntry::Occupied(mut o) = entity.entry::<Comp>() {
    o.insert(Comp(10));
}

assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 10);
Source

pub fn take(self) -> T

Removes the component from the entry and returns it.

§Examples
#[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
struct Comp(u32);

let mut entity = world.spawn(Comp(5));

if let ComponentEntry::Occupied(o) = entity.entry::<Comp>() {
    assert_eq!(o.take(), Comp(5));
}

assert_eq!(world.query::<&Comp>().iter(&world).len(), 0);
Source§

impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedComponentEntry<'w, 'a, T>

Source

pub fn get_mut(&mut self) -> Mut<'_, T>

Gets a mutable reference to the component in the entry.

If you need a reference to the OccupiedComponentEntry which may outlive the destruction of the OccupiedComponentEntry value, see into_mut.

§Examples
#[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
struct Comp(u32);

let mut entity = world.spawn(Comp(5));

if let ComponentEntry::Occupied(mut o) = entity.entry::<Comp>() {
    o.get_mut().0 += 10;
    assert_eq!(o.get().0, 15);

    // We can use the same Entry multiple times.
    o.get_mut().0 += 2
}

assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 17);
Source

pub fn into_mut(self) -> Mut<'a, T>

Converts the OccupiedComponentEntry into a mutable reference to the value in the entry with a lifetime bound to the EntityWorldMut.

If you need multiple references to the OccupiedComponentEntry, see get_mut.

§Examples
#[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
struct Comp(u32);

let mut entity = world.spawn(Comp(5));

if let ComponentEntry::Occupied(o) = entity.entry::<Comp>() {
    o.into_mut().0 += 10;
}

assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 15);

Auto Trait Implementations§

§

impl<'w, 'a, T> Freeze for OccupiedComponentEntry<'w, 'a, T>

§

impl<'w, 'a, T> !RefUnwindSafe for OccupiedComponentEntry<'w, 'a, T>

§

impl<'w, 'a, T> Send for OccupiedComponentEntry<'w, 'a, T>

§

impl<'w, 'a, T> Sync for OccupiedComponentEntry<'w, 'a, T>

§

impl<'w, 'a, T> Unpin for OccupiedComponentEntry<'w, 'a, T>
where T: Unpin,

§

impl<'w, 'a, T> !UnwindSafe for OccupiedComponentEntry<'w, 'a, T>

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

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
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> ConditionalSend for T
where T: Send,