pub struct Inject<T>(/* private fields */)
where
T: ?Sized;Expand description
A service from the container, as a handler or middleware argument.
Inject<T> dereferences to T.
use laravel::container::Inject;
pub struct Stripe { key: String }
impl Stripe { async fn charge(&self, cents: u64) {} }
async fn checkout(stripe: Inject<Stripe>) -> &'static str {
stripe.charge(2_000).await;
"Paid"
}T may be a trait object, such as Inject<dyn CacheStore>, registered with
[Registrar::instance_as], [Registrar::singleton_as], or [Registrar::bind_as]. Cloning an
Inject shares the same service and doesn’t require T: Clone.
If no service is registered as T, or building the service fails, the request fails with a
server error, and the framework reports the error.
Trait Implementations§
Source§impl<T> From<Arc<T>> for Inject<T>where
T: ?Sized,
Wraps a shared handle as an injection, such as to call a service function or a handler yourself
in a test.
impl<T> From<Arc<T>> for Inject<T>where
T: ?Sized,
Wraps a shared handle as an injection, such as to call a service function or a handler yourself in a test.
use std::sync::Arc;
use laravel::container::Inject;
pub struct Stripe;
let stripe: Inject<Stripe> = Arc::new(Stripe).into();Source§impl<T> From<Inject<T>> for Arc<T>where
T: ?Sized,
Converts the injection into the shared handle, to keep the service in another value’s
Arc<T> field.
impl<T> From<Inject<T>> for Arc<T>where
T: ?Sized,
Converts the injection into the shared handle, to keep the service in another value’s
Arc<T> field.
use std::sync::Arc;
use laravel::container::Inject;
pub struct Stripe;
pub struct Checkout { stripe: Arc<Stripe> }
async fn checkout(stripe: Inject<Stripe>) {
let checkout = Checkout { stripe: stripe.into() };
}Source§impl<S, T> FromRequestParts<S> for Inject<T>
impl<S, T> FromRequestParts<S> for Inject<T>
Auto Trait Implementations§
impl<T> Forget for Inject<T>where
T: ?Sized,
impl<T> Freeze for Inject<T>
impl<T> Move for Inject<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Inject<T>
impl<T> Send for Inject<T>
impl<T> Sync for Inject<T>
impl<T> Unpin for Inject<T>
impl<T> UnsafeUnpin for Inject<T>
impl<T> UnwindSafe for Inject<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<K> ForeignKey<K> for K
impl<K> ForeignKey<K> for K
impl<T> Formattable for T
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.