[−][src]Struct shaku_actix::Inject
Used to retrieve a reference to a component from a shaku Module
.
The module should be stored in Actix's app data, wrapped in an Arc
.
Use this struct as an extractor.
Example
use actix_web::{App, HttpServer, web}; use shaku::{module, Component, Interface}; use shaku_actix::Inject; use std::sync::Arc; trait HelloWorld: Interface { fn greet(&self) -> String; } #[derive(Component)] #[shaku(interface = HelloWorld)] struct HelloWorldImpl; impl HelloWorld for HelloWorldImpl { fn greet(&self) -> String { "Hello, world!".to_owned() } } module! { HelloModule { components = [HelloWorldImpl], providers = [] } } async fn hello(hello_world: Inject<HelloModule, dyn HelloWorld>) -> String { hello_world.greet() } #[actix_web::main] async fn main() -> std::io::Result<()> { let module = Arc::new(HelloModule::builder().build()); HttpServer::new(move || { App::new() .app_data(module.clone()) .route("/", web::get().to(hello)) }) .bind("127.0.0.1:8080")? .run() .await }
Trait Implementations
impl<M: Module + HasComponent<I>, I: Interface + ?Sized> Deref for Inject<M, I>
[src]
impl<M: Module + HasComponent<I>, I: Interface + ?Sized> FromRequest for Inject<M, I>
[src]
type Error = Error
The associated error which can be returned.
type Future = Ready<Result<Self, Error>>
Future that resolves to a Self
type Config = ()
Configuration for this extractor
pub fn from_request(
req: &HttpRequest,
_: &mut Payload<PayloadStream>
) -> Self::Future
[src]
req: &HttpRequest,
_: &mut Payload<PayloadStream>
) -> Self::Future
pub fn extract(req: &HttpRequest) -> Self::Future
[src]
pub fn configure<F>(f: F) -> Self::Config where
F: FnOnce(Self::Config) -> Self::Config,
[src]
F: FnOnce(Self::Config) -> Self::Config,
Auto Trait Implementations
impl<M, I: ?Sized> RefUnwindSafe for Inject<M, I> where
I: RefUnwindSafe,
M: RefUnwindSafe,
[src]
I: RefUnwindSafe,
M: RefUnwindSafe,
impl<M, I: ?Sized> Send for Inject<M, I>
[src]
impl<M, I: ?Sized> Sync for Inject<M, I>
[src]
impl<M, I: ?Sized> Unpin for Inject<M, I> where
M: Unpin,
[src]
M: Unpin,
impl<M, I: ?Sized> UnwindSafe for Inject<M, I> where
I: RefUnwindSafe,
M: UnwindSafe,
[src]
I: RefUnwindSafe,
M: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Interface for T where
T: Send + Sync + Any,
[src]
T: Send + Sync + Any,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ModuleInterface for T where
T: Send + Sync + Any,
[src]
T: Send + Sync + Any,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,