[][src]Struct object_provider::Request

pub struct Request<'r, 'out> { /* fields omitted */ }

A dynamic request for an object based on its type.

'r is the lifetime of request, and 'out is the lifetime of the requested reference.

Methods

impl<'r, 'out> Request<'r, 'out>[src]

pub fn provide<T: ?Sized + 'static>(
    self,
    value: &'out T
) -> ProvideResult<'r, 'out>
[src]

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

Returns Err(FulfilledRequest) if the value was successfully provided, and Ok(self) if T was not the type being requested.

This method can be chained within provide implementations using the ? operator to concisely provide multiple objects.

pub fn provide_with<T: ?Sized + 'static, F>(
    self,
    cb: F
) -> ProvideResult<'r, 'out> where
    F: FnOnce() -> &'out T, 
[src]

Lazily provides an object of type T in response to this request.

Returns Err(FulfilledRequest) if the value was successfully provided, and Ok(self) if T was not the type being requested.

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

This method can be chained within provide implementations using the ? operator to concisely provide multiple objects.

pub fn type_id(&self) -> TypeId[src]

Get the TypeId of the requested type.

pub fn is<T: ?Sized + 'static>(&self) -> bool[src]

Returns true if the requested type is the same as T

pub fn with<T: ?Sized + 'static, F>(f: F) -> Option<&'out T> where
    F: FnOnce(Request<'a, 'out>) -> ProvideResult<'a, 'out>, 
[src]

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

impl<'r, 'out> Debug for Request<'r, 'out>[src]

Auto Trait Implementations

impl<'r, 'out> !Send for Request<'r, 'out>

impl<'r, 'out> !Sync for Request<'r, 'out>

impl<'r, 'out> Unpin for Request<'r, 'out> where
    'out: 'r, 

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.