Struct Query

Source
pub struct Query<Q, U, D, R>
where Q: FnMut(&U) -> R, D: FnMut() -> R,
{ /* private fields */ }
Expand description

A query non-destructively creates some value R from references to a U. It can be called on values of any type T, not just on values of type U, so it requires a default R value for when it is called on values which are not a T.

This essentially lifts a FnMut(&U) -> R into a for<T> FnMut(&T) -> R.

Implementations§

Source§

impl<Q, U, R> Query<Q, U, fn() -> R, R>
where Q: FnMut(&U) -> R, R: Default,

Source

pub fn new(query: Q) -> Query<Q, U, fn() -> R, R>

Construct a new Query, returning R::default() for the cases where we query a value whose type is not U.

Source§

impl<Q, U, D, R> Query<Q, U, D, R>
where Q: FnMut(&U) -> R, D: FnMut() -> R,

Source

pub fn or_else(make_default: D, query: Q) -> Query<Q, U, D, R>

Construct a new Query, returning make_default() for the cases where we query a value whose type is not U.

Trait Implementations§

Source§

impl<Q, U: Debug, D, R: Debug> Debug for Query<Q, U, D, R>
where Q: FnMut(&U) -> R + Debug, D: FnMut() -> R + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Q, U, D, R> GenericQuery<R> for Query<Q, U, D, R>
where Q: FnMut(&U) -> R, D: FnMut() -> R,

Source§

fn query<T>(&mut self, t: &T) -> R
where T: Term,

Call the query function on any T.

Auto Trait Implementations§

§

impl<Q, U, D, R> Freeze for Query<Q, U, D, R>
where D: Freeze, Q: Freeze,

§

impl<Q, U, D, R> RefUnwindSafe for Query<Q, U, D, R>

§

impl<Q, U, D, R> Send for Query<Q, U, D, R>
where D: Send, Q: Send,

§

impl<Q, U, D, R> Sync for Query<Q, U, D, R>
where D: Sync, Q: Sync,

§

impl<Q, U, D, R> Unpin for Query<Q, U, D, R>
where D: Unpin, Q: Unpin,

§

impl<Q, U, D, R> UnwindSafe for Query<Q, U, D, R>
where D: UnwindSafe, Q: 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.