pub struct Expect<T>(/* private fields */);Expand description
A QueryData decorator which panics if its inner query does not match.
§Usage
As a query parameter, this decorator is useful for preventing systems from silently skipping over entities which may erroneously not match the query.
Consider the following erroneous example:
use bevy::prelude::*;
#[derive(Component)]
struct A;
#[derive(Component)]
struct B;
// A and B are always expected to be inserted together:
#[derive(Bundle)]
struct AB {
a: A,
b: B,
}
fn bad_system(mut commands: Commands) {
commands.spawn(A); // Spawn A without B!
}
fn unsafe_system(q: Query<(&A, &B)>) {
for _ in q.iter() {
// An instance of `A` does exist.
// But because `A` does not exist *with* `B`, this system skips over it silently.
}
}This problem can be solved with Expect:
use moonshine_util::expect::Expect;
fn safe_system(q: Query<(&A, Expect<&B>)>) {
for _ in q.iter() {
// This system will panic if it finds an instance of `A` without `B`.
}
}§Component Requirements
When used as a Component, this decorator will panic if the given component type T does
not exist on the entity. This is especially useful as a component requirement:
ⓘ
use moonshine_util::expect::Expect;
#[derive(Component)]
struct A;
#[derive(Component)]
#[require(Expect<A>)]
struct B;
fn unsafe_system(mut commands: Commands) {
commands.spawn(B); // Spawn B without A! This will panic!
}
Trait Implementations§
Source§impl<T> Component for Expect<T>where
T: Component,
impl<T> Component for Expect<T>where
T: Component,
Source§const STORAGE_TYPE: StorageType = StorageType::SparseSet
const STORAGE_TYPE: StorageType = StorageType::SparseSet
A constant indicating the storage type used for this component.
Source§type Mutability = Immutable
type Mutability = Immutable
A marker type to assist Bevy with determining if this component is
mutable, or immutable. Mutable components will have
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn register_required_components(
_component_id: ComponentId,
_required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _component_id: ComponentId, _required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Registers required components. Read more
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
Maps the entities on this component using the given
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreSource§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
Returns
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§impl<T> QueryData for Expect<T>where
T: QueryData,
impl<T> QueryData for Expect<T>where
T: QueryData,
Source§const IS_READ_ONLY: bool = true
const IS_READ_ONLY: bool = true
True if this query is read-only and may not perform mutable access.
Source§const IS_ARCHETYPAL: bool = T::IS_ARCHETYPAL
const IS_ARCHETYPAL: bool = T::IS_ARCHETYPAL
Returns true if (and only if) this query data relies strictly on archetypes to limit which
entities are accessed by the Query. Read more
Source§type ReadOnly = Expect<<T as QueryData>::ReadOnly>
type ReadOnly = Expect<<T as QueryData>::ReadOnly>
The read-only variant of this
QueryData, which satisfies the ReadOnlyQueryData trait.Source§type Item<'w, 's> = <T as QueryData>::Item<'w, 's>
type Item<'w, 's> = <T as QueryData>::Item<'w, 's>
The item returned by this
WorldQuery
This will be the data retrieved by the query,
and is visible to the end user when calling e.g. Query<Self>::get.Source§fn shrink<'wlong, 'wshort, 's>(
item: <Expect<T> as QueryData>::Item<'wlong, 's>,
) -> <Expect<T> as QueryData>::Item<'wshort, 's>where
'wlong: 'wshort,
fn shrink<'wlong, 'wshort, 's>(
item: <Expect<T> as QueryData>::Item<'wlong, 's>,
) -> <Expect<T> as QueryData>::Item<'wshort, 's>where
'wlong: 'wshort,
This function manually implements subtyping for the query items.
Source§unsafe fn fetch<'w, 's>(
state: &'s <Expect<T> as WorldQuery>::State,
fetch: &mut <Expect<T> as WorldQuery>::Fetch<'w>,
entity: Entity,
table_row: TableRow,
) -> Option<<Expect<T> as QueryData>::Item<'w, 's>>
unsafe fn fetch<'w, 's>( state: &'s <Expect<T> as WorldQuery>::State, fetch: &mut <Expect<T> as WorldQuery>::Fetch<'w>, entity: Entity, table_row: TableRow, ) -> Option<<Expect<T> as QueryData>::Item<'w, 's>>
Fetch
Self::Item for either the given entity in the current Table,
or for the given entity in the current Archetype. This must always be called after
WorldQuery::set_table with a table_row in the range of the current Table or after
WorldQuery::set_archetype with an entity in the current archetype.
Accesses components registered in WorldQuery::update_component_access. Read moreSource§fn iter_access(
state: &<Expect<T> as WorldQuery>::State,
) -> impl Iterator<Item = EcsAccessType<'_>>
fn iter_access( state: &<Expect<T> as WorldQuery>::State, ) -> impl Iterator<Item = EcsAccessType<'_>>
Returns an iterator over the access needed by
QueryData::fetch. Access conflicts are usually
checked in WorldQuery::update_component_access, but in certain cases this method can be useful to implement
a way of checking for access conflicts in a non-allocating way.Source§fn provide_extra_access(
_state: &mut Self::State,
_access: &mut Access,
_available_access: &Access,
)
fn provide_extra_access( _state: &mut Self::State, _access: &mut Access, _available_access: &Access, )
Offers additional access above what we requested in
update_component_access.
Implementations may add additional access that is a subset of available_access
and does not conflict with anything in access,
and must update access to include that access. Read moreSource§impl<T> WorldQuery for Expect<T>where
T: QueryData,
impl<T> WorldQuery for Expect<T>where
T: QueryData,
Source§const IS_DENSE: bool = T::IS_DENSE
const IS_DENSE: bool = T::IS_DENSE
Returns true if (and only if) every table of every archetype matched by this fetch contains
all of the matched components. Read more
Source§type Fetch<'w> = ExpectFetch<'w, T>
type Fetch<'w> = ExpectFetch<'w, T>
Per archetype/table state retrieved by this
WorldQuery to compute Self::Item for each entity.Source§type State = <T as WorldQuery>::State
type State = <T as WorldQuery>::State
State used to construct a
Self::Fetch. This will be cached inside QueryState,
so it is best to move as much data / computation here as possible to reduce the cost of
constructing Self::Fetch.Source§fn shrink_fetch<'wlong, 'wshort>(
fetch: <Expect<T> as WorldQuery>::Fetch<'wlong>,
) -> <Expect<T> as WorldQuery>::Fetch<'wshort>where
'wlong: 'wshort,
fn shrink_fetch<'wlong, 'wshort>(
fetch: <Expect<T> as WorldQuery>::Fetch<'wlong>,
) -> <Expect<T> as WorldQuery>::Fetch<'wshort>where
'wlong: 'wshort,
This function manually implements subtyping for the query fetches.
Source§unsafe fn init_fetch<'w>(
world: UnsafeWorldCell<'w>,
state: &<T as WorldQuery>::State,
last_run: Tick,
this_run: Tick,
) -> ExpectFetch<'w, T>
unsafe fn init_fetch<'w>( world: UnsafeWorldCell<'w>, state: &<T as WorldQuery>::State, last_run: Tick, this_run: Tick, ) -> ExpectFetch<'w, T>
Creates a new instance of
Self::Fetch,
by combining data from the World with the cached Self::State.
Readonly accesses resources registered in WorldQuery::update_component_access. Read moreSource§unsafe fn set_archetype<'w>(
fetch: &mut ExpectFetch<'w, T>,
state: &<T as WorldQuery>::State,
archetype: &'w Archetype,
table: &'w Table,
)
unsafe fn set_archetype<'w>( fetch: &mut ExpectFetch<'w, T>, state: &<T as WorldQuery>::State, archetype: &'w Archetype, table: &'w Table, )
Adjusts internal state to account for the next
Archetype. This will always be called on
archetypes that match this WorldQuery. Read moreSource§unsafe fn set_table<'w>(
fetch: &mut ExpectFetch<'w, T>,
state: &<T as WorldQuery>::State,
table: &'w Table,
)
unsafe fn set_table<'w>( fetch: &mut ExpectFetch<'w, T>, state: &<T as WorldQuery>::State, table: &'w Table, )
Adjusts internal state to account for the next
Table. This will always be called on tables
that match this WorldQuery. Read moreSource§fn update_component_access(
state: &<T as WorldQuery>::State,
access: &mut FilteredAccess,
)
fn update_component_access( state: &<T as WorldQuery>::State, access: &mut FilteredAccess, )
Source§fn get_state(
components: &Components,
) -> Option<<Expect<T> as WorldQuery>::State>
fn get_state( components: &Components, ) -> Option<<Expect<T> as WorldQuery>::State>
Source§fn init_state(world: &mut World) -> <T as WorldQuery>::State
fn init_state(world: &mut World) -> <T as WorldQuery>::State
Creates and initializes a
State for this WorldQuery type.Source§fn matches_component_set(
_state: &<T as WorldQuery>::State,
_set_contains_id: &impl Fn(ComponentId) -> bool,
) -> bool
fn matches_component_set( _state: &<T as WorldQuery>::State, _set_contains_id: &impl Fn(ComponentId) -> bool, ) -> bool
impl<T> ReadOnlyQueryData for Expect<T>where
T: ReadOnlyQueryData,
Auto Trait Implementations§
impl<T> Freeze for Expect<T>
impl<T> RefUnwindSafe for Expect<T>where
T: RefUnwindSafe,
impl<T> Send for Expect<T>where
T: Send,
impl<T> Sync for Expect<T>where
T: Sync,
impl<T> Unpin for Expect<T>where
T: Unpin,
impl<T> UnwindSafe for Expect<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<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Moves the components out of the bundle. Read more
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
Applies the after-effects of spawning this bundle. Read more
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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 moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.
Source§impl<T> Kind for Twhere
T: Component,
impl<T> Kind for Twhere
T: Component,
Source§type Filter = With<T>
type Filter = With<T>
The
QueryFilter which defines this kind.Source§fn debug_name() -> String
fn debug_name() -> String
Returns the debug name of this kind. Read more