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<'tmp, 'v: 'tmp, T: Component> IntoShiperator for Optional<&'tmp View<'v, T>>
impl<'tmp, 'v: 'tmp, T: Component> IntoShiperator for Optional<&'tmp View<'v, T>>
type Shiperator = Optional<FullRawWindow<'tmp, T>>
Source§fn into_shiperator(
self,
storage_ids: &mut ShipHashSet<StorageId>,
) -> (Self::Shiperator, usize, RawEntityIdAccess)
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
fn can_captain() -> bool
Returns
true
if the Shiperator can be a captain.Source§fn can_sailor() -> bool
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>>
impl<'tmp, 'v: 'tmp, T: Component, Track: Tracking> IntoShiperator for Optional<&'tmp ViewMut<'v, T, Track>>
type Shiperator = Optional<FullRawWindow<'tmp, T>>
Source§fn into_shiperator(
self,
storage_ids: &mut ShipHashSet<StorageId>,
) -> (Self::Shiperator, usize, RawEntityIdAccess)
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
fn can_captain() -> bool
Returns
true
if the Shiperator can be a captain.Source§fn can_sailor() -> bool
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>>
impl<'tmp, 'v: 'tmp, T: Component, Track: Tracking> IntoShiperator for Optional<&'tmp mut ViewMut<'v, T, Track>>
type Shiperator = Optional<FullRawWindowMut<'tmp, T, Track>>
Source§fn into_shiperator(
self,
storage_ids: &mut ShipHashSet<StorageId>,
) -> (Self::Shiperator, usize, RawEntityIdAccess)
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
fn can_captain() -> bool
Returns
true
if the Shiperator can be a captain.Source§fn can_sailor() -> bool
fn can_sailor() -> bool
Returns
true
if the Shiperator can be a sailor.Source§impl<'tmp, T: Component> ShiperatorCaptain for Optional<FullRawWindow<'tmp, T>>
impl<'tmp, T: Component> ShiperatorCaptain for Optional<FullRawWindow<'tmp, T>>
Source§unsafe fn get_captain_data(&self, _index: usize) -> Self::Out
unsafe fn get_captain_data(&self, _index: usize) -> Self::Out
Returns the component at
index
. Read moreSource§fn next_slice(&mut self)
fn next_slice(&mut self)
Shiperators might iterate multiple splices of
This function is called on the switch to the next slice.
EntityId
s.This function is called on the switch to the next slice.
Source§fn sail_time(&self) -> usize
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
This helps pick the fastest Shiperator when iterating multiple storages. Read more
Source§fn is_exact_sized(&self) -> bool
fn is_exact_sized(&self) -> bool
true
when this Shiperator cannot return None
.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,
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
unsafe fn get_captain_data(&self, _index: usize) -> Self::Out
Returns the component at
index
. Read moreSource§fn next_slice(&mut self)
fn next_slice(&mut self)
Shiperators might iterate multiple splices of
This function is called on the switch to the next slice.
EntityId
s.This function is called on the switch to the next slice.
Source§fn sail_time(&self) -> usize
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
This helps pick the fastest Shiperator when iterating multiple storages. Read more
Source§fn is_exact_sized(&self) -> bool
fn is_exact_sized(&self) -> bool
true
when this Shiperator cannot return None
.Source§impl<'tmp, T: Component> ShiperatorOutput for Optional<FullRawWindow<'tmp, T>>
impl<'tmp, T: Component> ShiperatorOutput for Optional<FullRawWindow<'tmp, T>>
Source§impl<'tmp, T: Component, Track> ShiperatorOutput for Optional<FullRawWindowMut<'tmp, T, Track>>where
FullRawWindowMut<'tmp, T, Track>: ShiperatorOutput,
impl<'tmp, T: Component, Track> ShiperatorOutput for Optional<FullRawWindowMut<'tmp, T, Track>>where
FullRawWindowMut<'tmp, T, Track>: ShiperatorOutput,
Source§impl<'tmp, T: Component> ShiperatorSailor for Optional<FullRawWindow<'tmp, T>>
impl<'tmp, T: Component> ShiperatorSailor for Optional<FullRawWindow<'tmp, T>>
Source§type Index = Option<usize>
type Index = Option<usize>
Type this Shiperator is indexed with.
This is often
This is often
usize
or a tuple of usize
for multiple storages.Source§unsafe fn get_sailor_data(&self, index: Self::Index) -> Self::Out
unsafe fn get_sailor_data(&self, index: Self::Index) -> Self::Out
Returns the component at
index
. Read moreSource§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>,
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 Index = Option<usize>
Type this Shiperator is indexed with.
This is often
This is often
usize
or a tuple of usize
for multiple storages.Source§unsafe fn get_sailor_data(&self, index: Self::Index) -> Self::Out
unsafe fn get_sailor_data(&self, index: Self::Index) -> Self::Out
Returns the component at
index
. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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