pub struct Single<'a, Q>(pub <Q as Query>::Item<'a>)
where
Q: Query;Expand description
A HandlerParam which fetches a single entity from the world.
If there isn’t exactly one entity that matches the Query, a runtime
panic occurs. This is useful for representing global variables or singleton
entities.
§Examples
use evenio::prelude::*;
#[derive(Component)]
struct MyComponent(i32);
let mut world = World::new();
world.add_handler(
|_: Receiver<E>, Single(MyComponent(data)): Single<&MyComponent>| {
println!("The data is: {data}");
},
);
let e = world.spawn();
world.insert(e, MyComponent(123));
world.send(E);Tuple Fields§
§0: <Q as Query>::Item<'a>Trait Implementations§
Source§impl<Q> HandlerParam for Single<'_, Q>where
Q: Query + 'static,
impl<Q> HandlerParam for Single<'_, Q>where
Q: Query + 'static,
Source§type This<'a> = Single<'a, Q>
type This<'a> = Single<'a, Q>
The type produced by this handler param. This must be the type
of
Self but with the lifetime of 'a.Source§fn init(
world: &mut World,
config: &mut HandlerConfig,
) -> Result<<Single<'_, Q> as HandlerParam>::State, InitError>
fn init( world: &mut World, config: &mut HandlerConfig, ) -> Result<<Single<'_, Q> as HandlerParam>::State, InitError>
Source§unsafe fn get<'a>(
state: &'a mut <Single<'_, Q> as HandlerParam>::State,
info: &'a HandlerInfo,
event_ptr: EventPtr<'a>,
target_location: EntityLocation,
world: UnsafeWorldCell<'a>,
) -> <Single<'_, Q> as HandlerParam>::This<'a>
unsafe fn get<'a>( state: &'a mut <Single<'_, Q> as HandlerParam>::State, info: &'a HandlerInfo, event_ptr: EventPtr<'a>, target_location: EntityLocation, world: UnsafeWorldCell<'a>, ) -> <Single<'_, Q> as HandlerParam>::This<'a>
Obtains a new instance of the handler parameter. Read more
Source§fn refresh_archetype(
state: &mut <Single<'_, Q> as HandlerParam>::State,
arch: &Archetype,
)
fn refresh_archetype( state: &mut <Single<'_, Q> as HandlerParam>::State, arch: &Archetype, )
Refresh an archetype for this handler param. Called whenever
Handler::refresh_archetype is called.Source§fn remove_archetype(
state: &mut <Single<'_, Q> as HandlerParam>::State,
arch: &Archetype,
)
fn remove_archetype( state: &mut <Single<'_, Q> as HandlerParam>::State, arch: &Archetype, )
Remove the given archetype for this handler param. Called whenever
Handler::remove_archetype is called.Source§impl<'a, Q> Ord for Single<'a, Q>
impl<'a, Q> Ord for Single<'a, Q>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<'a, Q> PartialOrd for Single<'a, Q>
impl<'a, Q> PartialOrd for Single<'a, Q>
impl<'a, Q> Copy for Single<'a, Q>
impl<'a, Q> Eq for Single<'a, Q>
impl<'a, Q> StructuralPartialEq for Single<'a, Q>where
Q: Query,
Auto Trait Implementations§
impl<'a, Q> Freeze for Single<'a, Q>
impl<'a, Q> RefUnwindSafe for Single<'a, Q>
impl<'a, Q> Send for Single<'a, Q>
impl<'a, Q> Sync for Single<'a, Q>
impl<'a, Q> Unpin for Single<'a, Q>
impl<'a, Q> UnwindSafe for Single<'a, Q>
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.