January 2019
Intermediate to advanced
520 pages
14h 32m
English
Insert the following code into a closure of the server::new function call:
let app = App::with_state(State::default()) .middleware(middleware::Logger::default()) .middleware(IdentityService::new( CookieIdentityPolicy::new(&[0; 32]) .name("auth-example") .secure(false), )) .middleware(Counter);
The App struct contains information about the state, middleware, and the scopes of routes. To set shared state to our application, we use the with_state method to construct the App instance. We create a default instance of the State struct, which is declared as follows:
#[derive(Default)]struct State(RefCell<i64>);
State contains a cell with an i64 value to count all requests. By default, it is created with a 0 value.
After this, we use ...
Read now
Unlock full access