Struct runtime_injector::RequestInfo [−][src]
pub struct RequestInfo { /* fields omitted */ }
Expand description
Information about an active request.
Implementations
impl RequestInfo
[src]
impl RequestInfo
[src]#[must_use]pub fn new() -> Self
[src]
#[must_use]pub fn new() -> Self
[src]Creates a new, empty instance of RequestInfo
.
#[must_use]pub fn with_request(&self, service: ServiceInfo) -> Self
[src]
#[must_use]pub fn with_request(&self, service: ServiceInfo) -> Self
[src]Creates a new child instance of RequestInfo
with the given service
appended to the end of the request path.
#[must_use]pub fn service_path(&self) -> &[ServiceInfo]
[src]
#[must_use]pub fn service_path(&self) -> &[ServiceInfo]
[src]Gets the current request path. This can be used to configure a service based on what it’s being injected into.
Example
use runtime_injector::{ Injector, IntoTransient, RequestInfo, ServiceInfo, Svc, }; struct Foo(pub Svc<Baz>); struct Bar(pub Svc<Baz>); struct Baz(pub i32); impl Baz { pub fn new(request_info: RequestInfo) -> Self { let service_path = request_info.service_path(); let value = match service_path.get(0) { Some(root) if root == &ServiceInfo::of::<Foo>() => 1, Some(root) if root == &ServiceInfo::of::<Bar>() => 2, _ => 0, }; Baz(value) } } let mut builder = Injector::builder(); builder.provide(Foo.transient()); builder.provide(Bar.transient()); builder.provide(Baz::new.transient()); let injector = builder.build(); let foo: Svc<Foo> = injector.get().unwrap(); let bar: Svc<Bar> = injector.get().unwrap(); let baz: Svc<Baz> = injector.get().unwrap(); assert_eq!(1, foo.0.0); assert_eq!(2, bar.0.0); assert_eq!(0, baz.0);
pub fn insert_parameter(
&mut self,
key: &str,
value: impl RequestParameter
) -> Option<Box<dyn RequestParameter>>
[src]
pub fn insert_parameter(
&mut self,
key: &str,
value: impl RequestParameter
) -> Option<Box<dyn RequestParameter>>
[src]Sets the value of a request parameter for the request. If a parameter has already been set to a value, then that value is returned.
pub fn remove_parameter(
&mut self,
key: &str
) -> Option<Box<dyn RequestParameter>>
[src]
pub fn remove_parameter(
&mut self,
key: &str
) -> Option<Box<dyn RequestParameter>>
[src]Removes and returns the value of a parameter if it has been set.
#[must_use]pub fn get_parameter(&self, key: &str) -> Option<&dyn RequestParameter>
[src]
#[must_use]pub fn get_parameter(&self, key: &str) -> Option<&dyn RequestParameter>
[src]Gets the value of a parameter if it has been set.
#[must_use]pub fn get_parameter_mut(
&mut self,
key: &str
) -> Option<&mut dyn RequestParameter>
[src]
#[must_use]pub fn get_parameter_mut(
&mut self,
key: &str
) -> Option<&mut dyn RequestParameter>
[src]Mutably gets the value of a parameter if it has been set.
Trait Implementations
impl Clone for RequestInfo
[src]
impl Clone for RequestInfo
[src]fn clone(&self) -> RequestInfo
[src]
fn clone(&self) -> RequestInfo
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for RequestInfo
[src]
impl Debug for RequestInfo
[src]impl Default for RequestInfo
[src]
impl Default for RequestInfo
[src]impl Request for RequestInfo
[src]
impl Request for RequestInfo
[src]Requests the information about the current request.
fn request(_injector: &Injector, info: &RequestInfo) -> InjectResult<Self>
[src]
fn request(_injector: &Injector, info: &RequestInfo) -> InjectResult<Self>
[src]Performs the request to the injector.
Auto Trait Implementations
impl !RefUnwindSafe for RequestInfo
impl Send for RequestInfo
impl Sync for RequestInfo
impl Unpin for RequestInfo
impl !UnwindSafe for RequestInfo
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more