Struct Request

Source
#[repr(C)]
pub struct Request<'a> { /* private fields */ }
Expand description

A dynamic request for an object based on its type.

Implementations§

Source§

impl<'a> Request<'a>

Source

pub fn provide_ref<T: ?Sized + 'static>( self: Pin<&mut Self>, value: &'a T, ) -> Pin<&mut Self>

Provides a reference of type &'a T in response to this request.

If a reference of type &'a T has already been provided for this request, the existing value will be replaced by the newly provided value.

This method can be chained within provide implementations to concisely provide multiple objects.

Source

pub fn provide_ref_with<T: ?Sized + 'static, F>( self: Pin<&mut Self>, cb: F, ) -> Pin<&mut Self>
where F: FnOnce() -> &'a T,

Lazily provides a reference of type &'a T in response to this request.

If a reference of type &'a T has already been provided for this request, the existing value will be replaced by the newly provided value.

The passed closure is only called if the value will be successfully provided.

This method can be chained within provide implementations to concisely provide multiple objects.

Source

pub fn provide_value<T: 'static>( self: Pin<&mut Self>, value: T, ) -> Pin<&mut Self>

Provides an value of type T in response to this request.

If a value of type T has already been provided for this request, the existing value will be replaced by the newly provided value.

This method can be chained within provide implementations to concisely provide multiple objects.

Source

pub fn provide_value_with<T: 'static, F>( self: Pin<&mut Self>, cb: F, ) -> Pin<&mut Self>
where F: FnOnce() -> T,

Lazily provides a value of type T in response to this request.

If a value of type T has already been provided for this request, the existing value will be replaced by the newly provided value.

The passed closure is only called if the value will be successfully provided.

This method can be chained within provide implementations to concisely provide multiple objects.

Source

pub fn is_ref<T: ?Sized + 'static>(&self) -> bool

Returns true if the requested type is &'a T

Source

pub fn is_value<T: 'static>(&self) -> bool

Returns true if the requested type is T

Source

pub fn request_ref<T: ?Sized + 'static, F>(f: F) -> Option<&'a T>
where F: FnOnce(Pin<&mut Request<'a>>),

Calls the provided closure with a request for the the type &'a T, returning Some(&T) if the request was fulfilled, and None otherwise.

The ObjectProviderExt trait provides helper methods specifically for types implementing ObjectProvider.

Source

pub fn request_value<T: 'static, F>(f: F) -> Option<T>
where F: FnOnce(Pin<&mut Request<'a>>),

Calls the provided closure with a request for the the type T, returning Some(T) if the request was fulfilled, and None otherwise.

The ObjectProviderExt trait provides helper methods specifically for types implementing ObjectProvider.

Trait Implementations§

Source§

impl<'a> Debug for Request<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Request<'a>

§

impl<'a> RefUnwindSafe for Request<'a>

§

impl<'a> Send for Request<'a>

§

impl<'a> Sync for Request<'a>

§

impl<'a> !Unpin for Request<'a>

§

impl<'a> UnwindSafe for Request<'a>

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.