Skip to content

Commit

Permalink
Use reference instead of Arc in Inject
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureMarker committed Feb 6, 2020
1 parent d44c8b0 commit 5c25ad8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions shaku_rocket/src/inject_component.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::ops::Deref;
use std::sync::Arc;

use rocket::outcome::IntoOutcome;
use rocket::request::{FromRequest, Outcome};
Expand Down Expand Up @@ -52,9 +51,9 @@ use shaku::{Container, Interface};
/// # }
/// }
/// ```
pub struct Inject<I: Interface + ?Sized>(Arc<I>);
pub struct Inject<'r, I: Interface + ?Sized>(&'r I);

impl<'a, 'r, I: Interface + ?Sized> FromRequest<'a, 'r> for Inject<I> {
impl<'a, 'r, I: Interface + ?Sized> FromRequest<'a, 'r> for Inject<'r, I> {
type Error = String;

fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
Expand All @@ -63,15 +62,15 @@ impl<'a, 'r, I: Interface + ?Sized> FromRequest<'a, 'r> for Inject<I> {
.map_failure(|f| (f.0, "Failed to retrieve container from state".to_string()))?;
let component = container
.inner()
.resolve::<I>()
.resolve_ref::<I>()
.map_err(|e| e.to_string())
.into_outcome(Status::InternalServerError)?;

Outcome::Success(Inject(component))
}
}

impl<I: Interface + ?Sized> Deref for Inject<I> {
impl<'r, I: Interface + ?Sized> Deref for Inject<'r, I> {
type Target = I;

fn deref(&self) -> &Self::Target {
Expand Down

0 comments on commit 5c25ad8

Please sign in to comment.