pub struct State<T>(pub Arc<T>);Expand description
Extracts application state.
Provides access to shared application state that was registered
with Rapina::state.
The inner value is wrapped in an Arc<T>, so extraction is always
a cheap atomic reference-count bump rather than a deep clone.
This also removes the Clone requirement on T.
§Examples
ⓘ
use rapina::prelude::*;
struct AppConfig {
db_url: String,
}
#[get("/config")]
async fn get_config(state: State<AppConfig>) -> String {
state.db_url.clone()
}Tuple Fields§
§0: Arc<T>Implementations§
Trait Implementations§
Source§impl<T: Send + Sync + 'static> FromRequestParts for State<T>
impl<T: Send + Sync + 'static> FromRequestParts for State<T>
Source§async fn from_request_parts(
_parts: &Parts,
_params: &PathParams,
state: &Arc<AppState>,
) -> Result<Self, Error>
async fn from_request_parts( _parts: &Parts, _params: &PathParams, state: &Arc<AppState>, ) -> Result<Self, Error>
Extract the value from request parts.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromRequest for Twhere
T: FromRequestParts,
impl<T> FromRequest for Twhere
T: FromRequestParts,
Source§async fn from_request(
req: Request<Incoming>,
params: &PathParams,
state: &Arc<AppState>,
) -> Result<T, Error>
async fn from_request( req: Request<Incoming>, params: &PathParams, state: &Arc<AppState>, ) -> Result<T, Error>
Extract the value from the request.