Struct shaku_rocket::Inject [−][src]
pub struct Inject<'r, M: ModuleInterface + HasComponent<I> + ?Sized, I: Interface + ?Sized>(_, _);
Expand description
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
#[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() } #[rocket::launch] fn rocket() -> _ { let module = HelloModule::builder().build(); rocket::build() .manage(Box::new(module)) .mount("/", routes![hello]) }
Trait Implementations
impl<'r, M: ModuleInterface + HasComponent<I> + ?Sized, I: Interface + ?Sized> Deref for Inject<'r, M, I>
[src]
impl<'r, M: ModuleInterface + HasComponent<I> + ?Sized, I: Interface + ?Sized> Deref for Inject<'r, M, I>
[src]impl<'r, M: ModuleInterface + HasComponent<I> + ?Sized, I: Interface + ?Sized> FromRequest<'r> for Inject<'r, M, I>
[src]
impl<'r, M: ModuleInterface + HasComponent<I> + ?Sized, I: Interface + ?Sized> FromRequest<'r> for Inject<'r, M, I>
[src]Auto Trait Implementations
impl<'r, M: ?Sized, I: ?Sized> RefUnwindSafe for Inject<'r, M, I> where
I: RefUnwindSafe,
M: RefUnwindSafe,
impl<'r, M: ?Sized, I: ?Sized> UnwindSafe for Inject<'r, M, I> where
I: RefUnwindSafe,
M: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
pub fn vzip(self) -> V
impl<T> Any for T where
T: Any,