Struct QueryUsing

Source
pub struct QueryUsing<'q, C, L: Lt> { /* private fields */ }
Expand description

Packs a context value of type C alongside the query that will be passed to a function fulfilling the query.

See Query::using().

Implementations§

Source§

impl<C, L: Lt> QueryUsing<'_, C, L>

Source

pub fn finish(self) -> Option<C>

Releases the context value, if still available.

Returns Some(_) if the query was not fulfilled, so the context was never used. Returns None if the query was fulfilled.

Source

pub fn is_fulfilled(&self) -> bool

Returns true if the query has been fulfilled and no values will be accepted in the future.

Source

pub fn expects<Tag: TagFor<L>>(&self) -> bool

Returns true if this query would accept a value tagged with Tag.

Note: this will return false if a value tagged with Tag was expected and has been fulfilled, as it will not accept additional values.

Source

pub fn expected_tag_id(&self) -> TagId

Returns the TagId expected by this query.

If this query has already been fulfilled, the returned ID is unspecified.

Source

pub fn put<Tag: TagFor<L>>(self, f: impl FnOnce(C) -> Tag::Value) -> Self

Attempts to fulfill the query using a function accepting C and returning a value marked by Tag.

If Tag is not expected, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Source

pub fn put_with_arg<Tag: TagFor<L>>( self, f: impl FnOnce(Tag::ArgValue, C) -> Tag::Value, ) -> Self

Attempts to fulfill the query using a function accepting Tag::ArgValue and C and returning a value marked by Tag.

If Tag is not expected, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Source

pub fn put_where<Tag: TagFor<L>>( self, predicate: impl FnOnce(&mut Tag::ArgValue, &mut C) -> bool, f: impl FnOnce(Tag::ArgValue, C) -> Tag::Value, ) -> Self

Behaves like Self::put_with_arg(), except that the query is not fulfilled if predicate returns false.

If Tag is not expected or predicate returns false, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Source

pub fn try_put<Tag: TagFor<L>>( self, f: impl FnOnce(C) -> Result<Tag::Value, C>, ) -> Self

Behaves like Self::put() when the given function returns Ok(_). When the function returns Err(context), the query is not fulfilled and the context will be usable again.

Source

pub fn try_put_with_arg<Tag: TagFor<L>>( self, f: impl FnOnce(Tag::ArgValue, C) -> Result<Tag::Value, (Tag::ArgValue, C)>, ) -> Self

Behaves like Self::put_with_arg() when the given function returns Ok(_). When the function returns Err((arg, context)), the query is not fulfilled and the context will be usable again.

Source

pub fn put_value<T: 'static>(self, f: impl FnOnce(C) -> T) -> Self

Attempts to fulfill the query using a function accepting C and returning a T marked by Value<T>.

If the value is not expected, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Source§

impl<'x, C, L: Lt> QueryUsing<'_, C, LtList<'x, L>>

Source

pub fn put_ref<T: 'static + ?Sized>(self, f: impl FnOnce(C) -> &'x T) -> Self

Attempts to fulfill the query using a function accepting C and returning a &'x T marked by Ref<Value<T>>.

If the reference is not expected, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Source

pub fn put_mut<T: 'static + ?Sized>( self, f: impl FnOnce(C) -> &'x mut T, ) -> Self

Attempts to fulfill the query using a function accepting C and returning a &'x mut T marked by Mut<Value<T>>.

If the reference is not expected, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Source

pub fn put_cloneable<T>(self, f: impl FnOnce(C) -> &'x T) -> Self
where T: 'static + Clone,

Attempts to fulfill the query using a function accepting C and returning a &'x T. This will supply the &'x T marked by Ref<Value<T>> as well as the T marked by Value<T> using T’s Clone implementation.

Behaves similarly to Self::put_ownable() but is available when the alloc feature is disabled.

If neither the reference nor the owned value are expected, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Source

pub fn put_ownable<T>(self, f: impl FnOnce(C) -> &'x T) -> Self
where T: 'static + ?Sized + ToOwned,

Available on crate feature alloc only.

Attempts to fulfill the query using a function accepting C and returning a &'x T. This will supply the &'x T marked by Ref<Value<T>> as well as the T::Owned marked by Value<T::Owned> using T's ToOwned implementation.

If neither the reference nor the owned value are expected, the function will not be called and the context will not be used. Does nothing if the query has already been fulfilled.

Auto Trait Implementations§

§

impl<'q, C, L> Freeze for QueryUsing<'q, C, L>
where C: Freeze,

§

impl<'q, C, L> !RefUnwindSafe for QueryUsing<'q, C, L>

§

impl<'q, C, L> !Send for QueryUsing<'q, C, L>

§

impl<'q, C, L> !Sync for QueryUsing<'q, C, L>

§

impl<'q, C, L> Unpin for QueryUsing<'q, C, L>
where C: Unpin,

§

impl<'q, C, L> !UnwindSafe for QueryUsing<'q, C, L>

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.