pub struct TrySingle<'a, Q>(pub Result<<Q as Query>::Item<'a>, SingleError>)
where
Q: Query;Expand description
Like Single, but contains a Result instead of panicking on error.
This is useful if you need to explicitly handle the situation where the query does not match exactly one entity.
Tuple Fields§
§0: Result<<Q as Query>::Item<'a>, SingleError>Methods from Deref<Target = Result<<Q as Query>::Item<'a>, SingleError>>§
1.0.0 · Sourcepub fn as_ref(&self) -> Result<&T, &E>
pub fn as_ref(&self) -> Result<&T, &E>
Converts from &Result<T, E> to Result<&T, &E>.
Produces a new Result, containing a reference
into the original, leaving the original in place.
§Examples
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.as_ref(), Ok(&2));
let x: Result<u32, &str> = Err("Error");
assert_eq!(x.as_ref(), Err(&"Error"));1.0.0 · Sourcepub fn as_mut(&mut self) -> Result<&mut T, &mut E>
pub fn as_mut(&mut self) -> Result<&mut T, &mut E>
Converts from &mut Result<T, E> to Result<&mut T, &mut E>.
§Examples
fn mutate(r: &mut Result<i32, i32>) {
match r.as_mut() {
Ok(v) => *v = 42,
Err(e) => *e = 0,
}
}
let mut x: Result<i32, i32> = Ok(2);
mutate(&mut x);
assert_eq!(x.unwrap(), 42);
let mut x: Result<i32, i32> = Err(13);
mutate(&mut x);
assert_eq!(x.unwrap_err(), 0);1.47.0 · Sourcepub fn as_deref(&self) -> Result<&<T as Deref>::Target, &E>where
T: Deref,
pub fn as_deref(&self) -> Result<&<T as Deref>::Target, &E>where
T: Deref,
Converts from Result<T, E> (or &Result<T, E>) to Result<&<T as Deref>::Target, &E>.
Coerces the Ok variant of the original Result via Deref
and returns the new Result.
§Examples
let x: Result<String, u32> = Ok("hello".to_string());
let y: Result<&str, &u32> = Ok("hello");
assert_eq!(x.as_deref(), y);
let x: Result<String, u32> = Err(42);
let y: Result<&str, &u32> = Err(&42);
assert_eq!(x.as_deref(), y);1.47.0 · Sourcepub fn as_deref_mut(&mut self) -> Result<&mut <T as Deref>::Target, &mut E>where
T: DerefMut,
pub fn as_deref_mut(&mut self) -> Result<&mut <T as Deref>::Target, &mut E>where
T: DerefMut,
Converts from Result<T, E> (or &mut Result<T, E>) to Result<&mut <T as DerefMut>::Target, &mut E>.
Coerces the Ok variant of the original Result via DerefMut
and returns the new Result.
§Examples
let mut s = "HELLO".to_string();
let mut x: Result<String, u32> = Ok("hello".to_string());
let y: Result<&mut str, &mut u32> = Ok(&mut s);
assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
let mut i = 42;
let mut x: Result<String, u32> = Err(42);
let y: Result<&mut str, &mut u32> = Err(&mut i);
assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);1.0.0 · Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns an iterator over the possibly contained value.
The iterator yields one value if the result is Result::Ok, otherwise none.
§Examples
let x: Result<u32, &str> = Ok(7);
assert_eq!(x.iter().next(), Some(&7));
let x: Result<u32, &str> = Err("nothing!");
assert_eq!(x.iter().next(), None);1.0.0 · Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Returns a mutable iterator over the possibly contained value.
The iterator yields one value if the result is Result::Ok, otherwise none.
§Examples
let mut x: Result<u32, &str> = Ok(7);
match x.iter_mut().next() {
Some(v) => *v = 40,
None => {},
}
assert_eq!(x, Ok(40));
let mut x: Result<u32, &str> = Err("nothing!");
assert_eq!(x.iter_mut().next(), None);Trait Implementations§
Source§impl<Q> HandlerParam for TrySingle<'_, Q>where
Q: Query + 'static,
impl<Q> HandlerParam for TrySingle<'_, Q>where
Q: Query + 'static,
Source§type This<'a> = TrySingle<'a, Q>
type This<'a> = TrySingle<'a, Q>
Self but with the lifetime of 'a.Source§fn init(
world: &mut World,
config: &mut HandlerConfig,
) -> Result<<TrySingle<'_, Q> as HandlerParam>::State, InitError>
fn init( world: &mut World, config: &mut HandlerConfig, ) -> Result<<TrySingle<'_, Q> as HandlerParam>::State, InitError>
Source§unsafe fn get<'a>(
state: &'a mut <TrySingle<'_, Q> as HandlerParam>::State,
_info: &'a HandlerInfo,
_event_ptr: EventPtr<'a>,
_target_location: EntityLocation,
world: UnsafeWorldCell<'a>,
) -> <TrySingle<'_, Q> as HandlerParam>::This<'a>
unsafe fn get<'a>( state: &'a mut <TrySingle<'_, Q> as HandlerParam>::State, _info: &'a HandlerInfo, _event_ptr: EventPtr<'a>, _target_location: EntityLocation, world: UnsafeWorldCell<'a>, ) -> <TrySingle<'_, Q> as HandlerParam>::This<'a>
Source§fn refresh_archetype(
state: &mut <TrySingle<'_, Q> as HandlerParam>::State,
arch: &Archetype,
)
fn refresh_archetype( state: &mut <TrySingle<'_, Q> as HandlerParam>::State, arch: &Archetype, )
Handler::refresh_archetype is called.Source§fn remove_archetype(
state: &mut <TrySingle<'_, Q> as HandlerParam>::State,
arch: &Archetype,
)
fn remove_archetype( state: &mut <TrySingle<'_, Q> as HandlerParam>::State, arch: &Archetype, )
Handler::remove_archetype is called.Source§impl<'a, Q> Ord for TrySingle<'a, Q>
impl<'a, Q> Ord for TrySingle<'a, Q>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, Q> PartialOrd for TrySingle<'a, Q>
impl<'a, Q> PartialOrd for TrySingle<'a, Q>
impl<'a, Q> Copy for TrySingle<'a, Q>
impl<'a, Q> Eq for TrySingle<'a, Q>
impl<'a, Q> StructuralPartialEq for TrySingle<'a, Q>where
Q: Query,
Auto Trait Implementations§
impl<'a, Q> Freeze for TrySingle<'a, Q>
impl<'a, Q> RefUnwindSafe for TrySingle<'a, Q>
impl<'a, Q> Send for TrySingle<'a, Q>
impl<'a, Q> Sync for TrySingle<'a, Q>
impl<'a, Q> Unpin for TrySingle<'a, Q>
impl<'a, Q> UnwindSafe for TrySingle<'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
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
key and return true if they are equal.