Skip to main content

State

Trait State 

Source
pub trait State: 'static {
    type Error;
}
Expand description

Application state used by web services.

A web::App is parameterized by a type that implements this trait. The state is available to handlers registered with Route::to_with_state(), and to filters, middleware, and services through their service context.

The associated Error type selects the application’s error domain, which is used by WebError and WebResponseError. Most applications use DefaultError.

The trait does not require Clone, but serving an application does: the server and HttpService clone the state for each connection.

use ntex::web;

#[derive(Clone)]
struct ApplicationState {
    greeting: String,
}

impl web::State for ApplicationState {
    type Error = web::DefaultError;
}

Required Associated Types§

Source

type Error

Error domain used by the application.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl State for ()

Implementors§

Source§

impl<T: 'static> State for AppState<T>