pub struct AsyncAppWithState<S> { /* private fields */ }Expand description
An Application whose route handlers are async functions.
State is stored as Arc<S> and passed by value (cheap clone) to each
handler invocation. Handlers receive owned Request, PathParams, and
ConnectionInfo values so the returned future is 'static.
Implementations§
Source§impl<S: Send + Sync + 'static> AsyncAppWithState<S>
impl<S: Send + Sync + 'static> AsyncAppWithState<S>
Sourcepub fn with_config(self, config: ServerConfig) -> Self
pub fn with_config(self, config: ServerConfig) -> Self
Pin the fallback App (used for any request this app’s own routes
don’t match) to an explicit crate::server_config::ServerConfig,
instead of reading RWS_CONFIG_* environment variables per request.
Mirrors App::with_config / crate::state::AppWithState::with_config.
Sourcepub fn route_entries(&self) -> Vec<RouteInfo>
pub fn route_entries(&self) -> Vec<RouteInfo>
Return a snapshot of all registered routes as (method, pattern) pairs.
Sourcepub fn get<F, Fut>(self, pattern: &str, handler: F) -> Selfwhere
F: Fn(Request, PathParams, ConnectionInfo, Arc<S>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Response> + Send + 'static,
pub fn get<F, Fut>(self, pattern: &str, handler: F) -> Selfwhere
F: Fn(Request, PathParams, ConnectionInfo, Arc<S>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Response> + Send + 'static,
Register an async GET handler for pattern.
Sourcepub fn post<F, Fut>(self, pattern: &str, handler: F) -> Selfwhere
F: Fn(Request, PathParams, ConnectionInfo, Arc<S>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Response> + Send + 'static,
pub fn post<F, Fut>(self, pattern: &str, handler: F) -> Selfwhere
F: Fn(Request, PathParams, ConnectionInfo, Arc<S>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Response> + Send + 'static,
Register an async POST handler for pattern.
Sourcepub fn put<F, Fut>(self, pattern: &str, handler: F) -> Selfwhere
F: Fn(Request, PathParams, ConnectionInfo, Arc<S>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Response> + Send + 'static,
pub fn put<F, Fut>(self, pattern: &str, handler: F) -> Selfwhere
F: Fn(Request, PathParams, ConnectionInfo, Arc<S>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Response> + Send + 'static,
Register an async PUT handler for pattern.
Trait Implementations§
Source§impl<S: Send + Sync + 'static> Application for AsyncAppWithState<S>
impl<S: Send + Sync + 'static> Application for AsyncAppWithState<S>
Source§fn execute(
&self,
request: &Request,
connection: &ConnectionInfo,
) -> Result<Response, String>
fn execute( &self, request: &Request, connection: &ConnectionInfo, ) -> Result<Response, String>
Receives a parsed request and returns a fully-built response.
Walk your controller list with
is_matching / process and return the first match.Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
true when executing request is quick and never waits on anything
but the local filesystem — health checks, metrics, small static files.
The async servers (HTTP/1.1, HTTP/2, HTTP/3) then call execute
directly on the event loop, as nginx does, instead of handing the
request to tokio’s blocking pool: that handoff (a shared lock and two
cross-thread wake-ups) costs more than serving a small file. Read moreSource§fn execute_async<'a>(
&'a self,
_request: &'a Request,
_connection: &'a ConnectionInfo,
) -> Option<AsyncResponse<'a>>
fn execute_async<'a>( &'a self, _request: &'a Request, _connection: &'a ConnectionInfo, ) -> Option<AsyncResponse<'a>>
An asynchronous version of
execute for this request, when the
application has one: the async servers await it on the connection’s
task instead of tying up a blocking-pool thread while it waits (the
config-driven proxy uses this to wait for a backend without holding a
thread). None (the default) means “use execute”. Wrappers return
Some only when they add no synchronous work of their own.Auto Trait Implementations§
impl<S> !RefUnwindSafe for AsyncAppWithState<S>
impl<S> !UnwindSafe for AsyncAppWithState<S>
impl<S> Freeze for AsyncAppWithState<S>
impl<S> Send for AsyncAppWithState<S>
impl<S> Sync for AsyncAppWithState<S>
impl<S> Unpin for AsyncAppWithState<S>
impl<S> UnsafeUnpin for AsyncAppWithState<S>
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