mirror of https://github.com/rwf2/Rocket.git
Group 'Rocket.state()' method with other accessors.
This commit is contained in:
parent
a19d9221d7
commit
1ba71cdb25
|
@ -586,26 +586,6 @@ impl Rocket {
|
|||
self
|
||||
}
|
||||
|
||||
/// Returns `Some` of the managed state value for the type `T` if it is
|
||||
/// being managed by this instance of Rocket. Otherwise, returns `None`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #[derive(PartialEq, Debug)]
|
||||
/// struct MyState(&'static str);
|
||||
///
|
||||
/// let rocket = rocket::ignite().manage(MyState("hello!"));
|
||||
/// assert_eq!(rocket.state::<MyState>(), Some(&MyState("hello!")));
|
||||
///
|
||||
/// let client = rocket::local::Client::new(rocket).expect("valid rocket");
|
||||
/// assert_eq!(client.rocket().state::<MyState>(), Some(&MyState("hello!")));
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
pub fn state<T: Send + Sync + 'static>(&self) -> Option<&T> {
|
||||
self.state.try_get()
|
||||
}
|
||||
|
||||
/// Attaches a fairing to this instance of Rocket.
|
||||
///
|
||||
/// # Example
|
||||
|
@ -746,6 +726,26 @@ impl Rocket {
|
|||
self.router.routes()
|
||||
}
|
||||
|
||||
/// Returns `Some` of the managed state value for the type `T` if it is
|
||||
/// being managed by `self`. Otherwise, returns `None`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #[derive(PartialEq, Debug)]
|
||||
/// struct MyState(&'static str);
|
||||
///
|
||||
/// let rocket = rocket::ignite().manage(MyState("hello!"));
|
||||
/// assert_eq!(rocket.state::<MyState>(), Some(&MyState("hello!")));
|
||||
///
|
||||
/// let client = rocket::local::Client::new(rocket).expect("valid rocket");
|
||||
/// assert_eq!(client.rocket().state::<MyState>(), Some(&MyState("hello!")));
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
pub fn state<T: Send + Sync + 'static>(&self) -> Option<&T> {
|
||||
self.state.try_get()
|
||||
}
|
||||
|
||||
/// Returns the active configuration.
|
||||
///
|
||||
/// # Example
|
||||
|
|
Loading…
Reference in New Issue