pub struct AppState { /* private fields */ }Expand description
Shared application state passed to all request handlers.
This struct is cloneable and cheap to clone since StandardEngine uses
Arc internally. Each handler receives a clone of this state.
§Example
ⓘ
let state = AppState::new(engine, QueryConfig::default());
// In an axum handler:
async fn handle_query(State(state): State<AppState>, ...) {
let engine = state.engine();
// ...
}Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(engine: StandardEngine, config: QueryConfig) -> Self
pub fn new(engine: StandardEngine, config: QueryConfig) -> Self
Create a new AppState with the given engine and configuration.
Sourcepub fn engine(&self) -> &StandardEngine
pub fn engine(&self) -> &StandardEngine
Get a reference to the database engine.
Sourcepub fn engine_clone(&self) -> StandardEngine
pub fn engine_clone(&self) -> StandardEngine
Get a clone of the database engine.
This is cheap since StandardEngine uses Arc internally.
Sourcepub fn config(&self) -> &QueryConfig
pub fn config(&self) -> &QueryConfig
Get a reference to the query configuration.
Sourcepub fn query_timeout(&self) -> Duration
pub fn query_timeout(&self) -> Duration
Get the query timeout from configuration.
Sourcepub fn request_timeout(&self) -> Duration
pub fn request_timeout(&self) -> Duration
Get the request timeout from configuration.
Sourcepub fn max_connections(&self) -> usize
pub fn max_connections(&self) -> usize
Get the maximum connections from configuration.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AppState
impl !RefUnwindSafe for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl !UnwindSafe for AppState
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)