pub struct QuerySocketBuilder<T> { /* private fields */ }Expand description
Route builder that expects and deserialises URL query parameters of type T.
Obtained from ServerMechanism::query. Optionally attach shared state via
state, or finalise immediately with
onconnect /
onconnect_sync.
Implementations§
Source§impl<T: DeserializeOwned + Send + 'static> QuerySocketBuilder<T>
impl<T: DeserializeOwned + Send + 'static> QuerySocketBuilder<T>
Sourcepub fn onconnect<F, Fut, Re>(self, handler: F) -> SocketType
pub fn onconnect<F, Fut, Re>(self, handler: F) -> SocketType
Finalises this route with an async handler that receives the deserialised query parameters.
Before the handler is called, the URL query string (?field=value&...) is parsed
and deserialised into T. The handler receives a ready-to-use T — no manual
parsing is needed. A missing or malformed query string is rejected before the
handler is ever invoked.
The handler must return Result<impl Reply, Rejection>.
Returns a SocketType ready to be passed to Server::mechanism.
Sourcepub unsafe fn onconnect_sync<F, Re>(self, handler: F) -> SocketType
pub unsafe fn onconnect_sync<F, Re>(self, handler: F) -> SocketType
Finalises this route with a synchronous handler that receives the deserialised query parameters.
The query string is decoded into T before the handler is dispatched, identical to
the async variant. The closure may block but must complete quickly.
Returns a SocketType ready to be passed to Server::mechanism.
§Safety
Every incoming request spawns an independent task on Tokio’s blocking thread pool.
The pool caps the number of live OS threads (default 512), but the queue of waiting
tasks is unbounded — under a traffic surge, tasks accumulate without limit, consuming
unbounded memory and causing severe latency spikes or OOM crashes before any queued task
gets a chance to run. Additionally, any panic inside the handler is silently converted
into a Rejection, masking runtime errors. Callers must ensure the handler completes
quickly and that adequate backpressure or rate limiting is applied externally.
Sourcepub fn state<S: Clone + Send + Sync + 'static>(
self,
state: S,
) -> StatefulQuerySocketBuilder<T, S>
pub fn state<S: Clone + Send + Sync + 'static>( self, state: S, ) -> StatefulQuerySocketBuilder<T, S>
Attaches shared state S, transitioning to StatefulQuerySocketBuilder.
Alternative ordering to .state(s).query::<T>() — both produce the same route.
A fresh clone of S is injected alongside the query-decoded T on every request.
The handler will receive (state: S, query: T).
S must be Clone + Send + Sync + 'static.