Struct shaku_rocket::Inject[][src]

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

Used to retrieve a reference to a component from a shaku Module. The module should be stored in Rocket's state, in a Box (It could be Box<dyn MyModule> if the module implementation changes at runtime). Use this Inject struct as a request guard.

Example

#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;

use shaku::{module, Component, Interface};
use shaku_rocket::Inject;

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 = []
    }
}

#[get("/")]
fn hello(hello_world: Inject<HelloModule, dyn HelloWorld>) -> String {
    hello_world.greet()
}

fn main() {
    let module = HelloModule::builder().build();

    rocket::ignite()
        .manage(Box::new(module))
        .mount("/", routes![hello])
        .launch();
}

Trait Implementations

impl<'r, M: ModuleInterface + HasComponent<I> + ?Sized, I: Interface + ?Sized> Deref for Inject<'r, M, I>[src]

type Target = I

The resulting type after dereferencing.

impl<'a, 'r, M: ModuleInterface + HasComponent<I> + ?Sized, I: Interface + ?Sized> FromRequest<'a, 'r> for Inject<'r, M, I>[src]

type Error = String

The associated error to be returned if derivation fails.

Auto Trait Implementations

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

impl<'r, M: ?Sized, I: ?Sized> Send for Inject<'r, M, I>[src]

impl<'r, M: ?Sized, I: ?Sized> Sync for Inject<'r, M, I>[src]

impl<'r, M: ?Sized, I: ?Sized> Unpin for Inject<'r, M, I> where
    M: Unpin
[src]

impl<'r, M: ?Sized, I: ?Sized> UnwindSafe for Inject<'r, 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, I> AsResult<T, I> for T where
    I: Input, 

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> Interface for T where
    T: Send + Sync + Any
[src]

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

impl<T> IntoCollection<T> for T

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<T> Typeable for T where
    T: Any

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