[][src]Struct shaku_actix::Inject

pub struct Inject<M: Module + HasComponent<I>, I: Interface + ?Sized>(_, _);

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]

type Target = I

The resulting type after dereferencing.

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

Auto Trait Implementations

impl<M, I: ?Sized> RefUnwindSafe for Inject<M, I> where
    I: RefUnwindSafe,
    M: RefUnwindSafe
[src]

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]

impl<M, I: ?Sized> UnwindSafe for Inject<M, I> where
    I: RefUnwindSafe,
    M: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T> Interface for T where
    T: Send + Sync + Any
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ModuleInterface for T where
    T: Send + Sync + Any
[src]

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,