pub struct State<T>(pub Arc<T>);Expand description
Extracts a shared handle to application state of type T.
The state must have been registered with
AppBuilder::state; if no value of type T was
registered, extraction fails with 500 Internal Server Error. State<T>
derefs to T, so the inner value can be used directly.
use churust_core::{Churust, State, TestClient};
#[derive(Clone)]
struct Config { greeting: &'static str }
let app = Churust::server()
.state(Config { greeting: "hi" })
.routing(|r| {
r.get("/", |cfg: State<Config>| async move { cfg.greeting });
})
.build();
let res = TestClient::new(app).get("/").send().await;
assert_eq!(res.text(), "hi");Tuple Fields§
§0: Arc<T>The shared handle to the registered state value.
Trait Implementations§
Source§impl<T> FromCallParts for State<T>
impl<T> FromCallParts for State<T>
Auto Trait Implementations§
impl<T> Freeze for State<T>
impl<T> RefUnwindSafe for State<T>where
T: RefUnwindSafe,
impl<T> Send for State<T>
impl<T> Sync for State<T>
impl<T> Unpin for State<T>
impl<T> UnsafeUnpin for State<T>
impl<T> UnwindSafe for State<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more