Function tide::with_state [−][src]
Expand description
Create a new Tide server with shared application scoped state.
Application scoped state is useful for storing items
Examples
use tide::Request;
/// The shared application state.
#[derive(Clone)]
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))
});
app.listen("127.0.0.1:8080").await?;