Optional

Struct Optional 

Source
pub struct Optional<T>(pub T);
Expand description

Allows iteration over a component that may be absent.

§Example:

use shipyard::{Component, IntoIter, View, World};

#[derive(Component, PartialEq, Eq, Debug)]
struct A(u32);

#[derive(Component, PartialEq, Eq, Debug)]
struct B(u32);

let mut world = World::new();

world.add_entity((A(0),));
world.add_entity((A(1), B(10)));

let (a, b) = world.borrow::<(View<A>, View<B>)>().unwrap();
let mut iter = (&a, b.as_optional()).iter();

assert_eq!(iter.next(), Some((&A(0), None)));
assert_eq!(iter.next(), Some((&A(1), Some(&B(10)))));

Tuple Fields§

§0: T

Trait Implementations§

Source§

impl<T: Clone> Clone for Optional<T>

Source§

fn clone(&self) -> Optional<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'tmp, 'v: 'tmp, T: Component> IntoShiperator for Optional<&'tmp View<'v, T>>

Source§

type Shiperator = Optional<FullRawWindow<'tmp, T>>

Source§

fn into_shiperator( self, storage_ids: &mut ShipHashSet<StorageId>, ) -> (Self::Shiperator, usize, RawEntityIdAccess)

Returns the Shiperator, its maximum length and RawEntityIdAccess.
Source§

fn can_captain() -> bool

Returns true if the Shiperator can be a captain.
Source§

fn can_sailor() -> bool

Returns true if the Shiperator can be a sailor.
Source§

impl<'tmp, 'v: 'tmp, T: Component, Track: Tracking> IntoShiperator for Optional<&'tmp ViewMut<'v, T, Track>>

Source§

type Shiperator = Optional<FullRawWindow<'tmp, T>>

Source§

fn into_shiperator( self, storage_ids: &mut ShipHashSet<StorageId>, ) -> (Self::Shiperator, usize, RawEntityIdAccess)

Returns the Shiperator, its maximum length and RawEntityIdAccess.
Source§

fn can_captain() -> bool

Returns true if the Shiperator can be a captain.
Source§

fn can_sailor() -> bool

Returns true if the Shiperator can be a sailor.
Source§

impl<'tmp, 'v: 'tmp, T: Component, Track: Tracking> IntoShiperator for Optional<&'tmp mut ViewMut<'v, T, Track>>

Source§

type Shiperator = Optional<FullRawWindowMut<'tmp, T, Track>>

Source§

fn into_shiperator( self, storage_ids: &mut ShipHashSet<StorageId>, ) -> (Self::Shiperator, usize, RawEntityIdAccess)

Returns the Shiperator, its maximum length and RawEntityIdAccess.
Source§

fn can_captain() -> bool

Returns true if the Shiperator can be a captain.
Source§

fn can_sailor() -> bool

Returns true if the Shiperator can be a sailor.
Source§

impl<'tmp, T: Component> ShiperatorCaptain for Optional<FullRawWindow<'tmp, T>>

Source§

unsafe fn get_captain_data(&self, _index: usize) -> Self::Out

Returns the component at index. Read more
Source§

fn next_slice(&mut self)

Shiperators might iterate multiple splices of EntityIds.
This function is called on the switch to the next slice.
Source§

fn sail_time(&self) -> usize

Approximation of how much time iterating this Shiperator will take.
This helps pick the fastest Shiperator when iterating multiple storages. Read more
Source§

fn is_exact_sized(&self) -> bool

true when this Shiperator cannot return None.
Source§

fn unpick(&mut self)

By default into_shiperator returns Shiperators that thinks they are captains.
This function is called on the ones that end up not being picked.
Source§

impl<'tmp, T: Component, Track> ShiperatorCaptain for Optional<FullRawWindowMut<'tmp, T, Track>>
where Optional<FullRawWindowMut<'tmp, T, Track>>: ShiperatorOutput, FullRawWindowMut<'tmp, T, Track>: ShiperatorCaptain,

Source§

unsafe fn get_captain_data(&self, _index: usize) -> Self::Out

Returns the component at index. Read more
Source§

fn next_slice(&mut self)

Shiperators might iterate multiple splices of EntityIds.
This function is called on the switch to the next slice.
Source§

fn sail_time(&self) -> usize

Approximation of how much time iterating this Shiperator will take.
This helps pick the fastest Shiperator when iterating multiple storages. Read more
Source§

fn is_exact_sized(&self) -> bool

true when this Shiperator cannot return None.
Source§

fn unpick(&mut self)

By default into_shiperator returns Shiperators that thinks they are captains.
This function is called on the ones that end up not being picked.
Source§

impl<'tmp, T: Component> ShiperatorOutput for Optional<FullRawWindow<'tmp, T>>

Source§

type Out = Option<&'tmp T>

The type returned by the Shiperator.
Source§

impl<'tmp, T: Component, Track> ShiperatorOutput for Optional<FullRawWindowMut<'tmp, T, Track>>
where FullRawWindowMut<'tmp, T, Track>: ShiperatorOutput,

Source§

type Out = Option<<FullRawWindowMut<'tmp, T, Track> as ShiperatorOutput>::Out>

The type returned by the Shiperator.
Source§

impl<'tmp, T: Component> ShiperatorSailor for Optional<FullRawWindow<'tmp, T>>

Source§

type Index = Option<usize>

Type this Shiperator is indexed with.
This is often usize or a tuple of usize for multiple storages.
Source§

unsafe fn get_sailor_data(&self, index: Self::Index) -> Self::Out

Returns the component at index. Read more
Source§

fn indices_of(&self, entity_id: EntityId, index: usize) -> Option<Self::Index>

Returns the index of the component with id entity_id.
Source§

fn index_from_usize(_index: usize) -> Self::Index

When a Mixed iterator flags a storage as captain, it can skip indices_of and directly use index for this one Shiperator.
But at the type level there is no way to express this since the captain is picked at runtime. Read more
Source§

impl<'tmp, T: Component, Track> ShiperatorSailor for Optional<FullRawWindowMut<'tmp, T, Track>>
where Optional<FullRawWindowMut<'tmp, T, Track>>: ShiperatorOutput<Out = Option<<FullRawWindowMut<'tmp, T, Track> as ShiperatorOutput>::Out>>, FullRawWindowMut<'tmp, T, Track>: ShiperatorSailor<Index = usize>,

Source§

type Index = Option<usize>

Type this Shiperator is indexed with.
This is often usize or a tuple of usize for multiple storages.
Source§

unsafe fn get_sailor_data(&self, index: Self::Index) -> Self::Out

Returns the component at index. Read more
Source§

fn indices_of(&self, entity_id: EntityId, index: usize) -> Option<Self::Index>

Returns the index of the component with id entity_id.
Source§

fn index_from_usize(_index: usize) -> Self::Index

When a Mixed iterator flags a storage as captain, it can skip indices_of and directly use index for this one Shiperator.
But at the type level there is no way to express this since the captain is picked at runtime. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Optional<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Optional<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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more