pub struct TransientAsyncProvider<T> { /* private fields */ }
Expand description
Represents a specialized Provider
.
Use the transient_async
function to create this provider.
Implementations§
Source§impl<T> TransientAsyncProvider<T>
impl<T> TransientAsyncProvider<T>
Sourcepub fn eager_create(self, eager_create: bool) -> Self
pub fn eager_create(self, eager_create: bool) -> Self
Sets whether the provider is eager to create.
Source§impl<T: 'static> TransientAsyncProvider<T>
impl<T: 'static> TransientAsyncProvider<T>
Sourcepub fn bind<U, F>(self, transform: F) -> Self
pub fn bind<U, F>(self, transform: F) -> Self
Create a provider of type Provider<U>
, save it to the current provider.
This method accepts a parameter of fn(T) -> U
, which in combination
with the current provider’s constructor of type async fn(&mut Context) -> T
,
creates a Provider<U>
with constructor async fn(&mut Context) -> U
and other fields consistent with the current provider.
All bound providers will be registered together
when the current provider is registered in the Context
.
§Example
use std::{fmt::Debug, rc::Rc, sync::Arc};
use rudi::{transient_async, FutureExt, Provider, TransientAsyncProvider};
#[derive(Clone, Debug)]
struct A(i32);
fn into_debug(a: A) -> Rc<dyn Debug> {
Rc::new(a)
}
fn main() {
let p: TransientAsyncProvider<A> =
transient_async(|cx| async { A(cx.resolve_async().await) }.boxed())
.bind(Rc::new)
.bind(Arc::new)
.bind(Box::new)
.bind(into_debug);
let p: Provider<A> = p.into();
assert_eq!(p.binding_definitions().unwrap().len(), 4);
}
Trait Implementations§
Source§impl<T: 'static> From<TransientAsyncProvider<T>> for DynProvider
impl<T: 'static> From<TransientAsyncProvider<T>> for DynProvider
Source§fn from(value: TransientAsyncProvider<T>) -> Self
fn from(value: TransientAsyncProvider<T>) -> Self
Converts to this type from the input type.
Source§impl<T: 'static> From<TransientAsyncProvider<T>> for Provider<T>
impl<T: 'static> From<TransientAsyncProvider<T>> for Provider<T>
Source§fn from(value: TransientAsyncProvider<T>) -> Self
fn from(value: TransientAsyncProvider<T>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<T> Freeze for TransientAsyncProvider<T>
impl<T> !RefUnwindSafe for TransientAsyncProvider<T>
impl<T> !Send for TransientAsyncProvider<T>
impl<T> !Sync for TransientAsyncProvider<T>
impl<T> Unpin for TransientAsyncProvider<T>
impl<T> !UnwindSafe for TransientAsyncProvider<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more