pub struct Inject<T>(pub Arc<T>)
where
T: ?Sized;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 for Inject<T>where
T: Eq,
Source§impl<T> Extract for Inject<T>
Extract implementation for Inject<T> where T: Sized + Send + Sync + 'static.
impl<T> 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.
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