Trait Provide

Source
pub trait Provide<L: Lt = ()>: Sized {
    // Required method
    fn provide(self, query: &mut Query<'_, L>) -> Option<Self>;

    // Provided methods
    fn request<Tag: TagFor<L>>(
        self,
        arg: Tag::ArgValue,
    ) -> Result<Tag::Value, Self> { ... }
    fn request_value<T: 'static>(self) -> Result<T, Self> { ... }
    fn request_ref<'x, T: 'static + ?Sized>(self) -> Result<&'x T, Self>
       where Ref<Value<T>>: TagFor<L, ArgValue = (), Value = &'x T> { ... }
    fn request_mut<'x, T: 'static + ?Sized>(self) -> Result<&'x mut T, Self>
       where Mut<Value<T>>: TagFor<L, ArgValue = (), Value = &'x mut T> { ... }
}
Expand description

Provides access to values of arbitrary type.

Requested values are specified using a ResourceTag implementation, or to be more specific, a TagFor<L> implementation.

Required Methods§

Source

fn provide(self, query: &mut Query<'_, L>) -> Option<Self>

Supplies the requested value to the given Query, if available.

Implementations are expected to return Some(self) if the query was not fulfilled.

Provided Methods§

Source

fn request<Tag: TagFor<L>>(self, arg: Tag::ArgValue) -> Result<Tag::Value, Self>

Requests the value specified by Tag. Returns Err(self) if the value was not available.

arg should contain whatever data is needed to request the tagged type. If no arguments are necessary, this will usually be the unit type ().

Source

fn request_value<T: 'static>(self) -> Result<T, Self>

Requests a value of type T, marked by the tag Value<T>. Values of type T must not hold any borrowed data.

Source

fn request_ref<'x, T: 'static + ?Sized>(self) -> Result<&'x T, Self>
where Ref<Value<T>>: TagFor<L, ArgValue = (), Value = &'x T>,

Requests a shared reference to a value of type T, marked by the tag Ref<Value<T>>. Values of type T must not hold any borrowed data.

Source

fn request_mut<'x, T: 'static + ?Sized>(self) -> Result<&'x mut T, Self>
where Mut<Value<T>>: TagFor<L, ArgValue = (), Value = &'x mut T>,

Requests a unique reference to a value of type T, marked by the tag Mut<Value<T>>. Values of type T must not hold any borrowed data.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'data, L: Lt + 'data> Provide<L> for Box<dyn ProvideBox<L> + 'data>

Available on crate feature alloc only.
Source§

fn provide(self, query: &mut Query<'_, L>) -> Option<Self>

Source§

impl<'data, L: Lt + 'data> Provide<L> for Box<dyn ProvideBox<L> + Send + 'data>

Available on crate feature alloc only.
Source§

fn provide(self, query: &mut Query<'_, L>) -> Option<Self>

Source§

impl<'data, L: Lt + 'data> Provide<L> for Box<dyn ProvideBox<L> + Send + Sync + 'data>

Available on crate feature alloc only.
Source§

fn provide(self, query: &mut Query<'_, L>) -> Option<Self>

Source§

impl<'x, P: ?Sized + ProvideRef<LTail>, LTail: Lt> Provide<(Lifetime<'x>, LTail)> for &'x P

Source§

fn provide(self, query: &mut Query<'_, LtList<'x, LTail>>) -> Option<Self>

Source§

impl<'x, P: ?Sized + ProvideRef<LTail>, LTail: Lt> Provide<(Lifetime<'x>, LTail)> for &'x mut P

Source§

fn provide(self, query: &mut Query<'_, LtList<'x, LTail>>) -> Option<Self>

Source§

impl<L: Lt> Provide<L> for Infallible

Source§

fn provide(self, _: &mut Query<'_, L>) -> Option<Self>

Source§

impl<L: Lt> Provide<L> for ()

Source§

fn provide(self, _: &mut Query<'_, L>) -> Option<Self>

Source§

impl<L: Lt> Provide<L> for String

Available on crate feature alloc only.
Source§

fn provide(self, query: &mut Query<'_, L>) -> Option<Self>

Source§

impl<L: Lt, P: Provide<L>> Provide<L> for Option<P>

Source§

fn provide(self, query: &mut Query<'_, L>) -> Option<Self>

Source§

fn request<Tag: TagFor<L>>(self, arg: Tag::ArgValue) -> Result<Tag::Value, Self>

Implementors§