pub struct Inject<T: ?Sized>(pub Arc<T>);Expand description
A wrapper around Arc<T> that can be extracted from a ResolveContext.
T may be unsized (dyn Trait) for trait-object injection set up with
bind!(dyn Trait => Concrete). For sized concrete types the standard
Extract impl applies; for dyn Trait the generated provider code uses
ctx.resolve_external::<Arc<dyn Trait>>() directly (no Extract impl
needed — and no orphan-rule violation).
§Examples
ⓘ
// Concrete injectable type
pub struct UserService { db: Inject<Database> }
// Trait-object injection (set up with bind!)
pub struct NotificationService { mailer: Inject<dyn Mailer> }
// Axum handler destructuring pattern
async fn handler(Inject(svc): Inject<UserService>) -> impl IntoResponse { ... }Tuple Fields§
§0: Arc<T>Implementations§
Trait Implementations§
impl<T: Eq> Eq for Inject<T>
Source§impl<T: Sized + Send + Sync + 'static> Extract for Inject<T>
Extract implementation for Inject<T> where T: Sized + Send + Sync + 'static.
impl<T: Sized + Send + Sync + 'static> Extract for Inject<T>
Extract implementation for Inject<T> where T: Sized + Send + Sync + 'static.
Resolution order:
- Try
resolve_external::<Arc<T>>()— findsInjectableArcFactoryentries submitted by#[injectable]macros. These entries callresolve_singleton_arcinternally, so singletons are properly cached. - Fall back to
resolve_external::<T>()— findsDynProvider<T>registrations for external types, then wraps the result inArc::new.
Source§fn extract<'life0, 'async_trait>(
ctx: &'life0 ResolveContext,
) -> Pin<Box<dyn Future<Output = InjectableResult<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn extract<'life0, 'async_trait>(
ctx: &'life0 ResolveContext,
) -> Pin<Box<dyn Future<Output = InjectableResult<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Extract a value from the given resolution context. Read more
Auto Trait Implementations§
impl<T> Freeze for Inject<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Inject<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for Inject<T>
impl<T> Sync for Inject<T>
impl<T> Unpin for Inject<T>where
T: ?Sized,
impl<T> UnsafeUnpin for Inject<T>where
T: ?Sized,
impl<T> UnwindSafe for Inject<T>where
T: RefUnwindSafe + ?Sized,
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