[][src]Function tide::with_state

pub fn with_state<State>(state: State) -> Server<State> where
    State: Send + Sync + 'static, 

Create a new Tide server with shared application scoped state.

Application scoped state is useful for storing items


use tide::Request;

/// The shared application state.
struct State {
    name: String,

// Define a new instance of the state.
let state = State {
    name: "Nori".to_string()

// Initialize the application with state.
let mut app = tide::with_state(state);
app.at("/").get(|req: Request<State>| async move {
    Ok(format!("Hello, {}!", &req.state().name))