From 115b30d9ccf52c9f19609bf13862dfdd58b99d0b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 2 Mar 2019 22:11:24 -0800 Subject: [PATCH] add state example --- src/app.rs | 21 ++++++++++++++++ src/extractor.rs | 65 ++++++++---------------------------------------- 2 files changed, 31 insertions(+), 55 deletions(-) diff --git a/src/app.rs b/src/app.rs index ae510621..e9b10081 100644 --- a/src/app.rs +++ b/src/app.rs @@ -79,6 +79,27 @@ where /// multiple times. If you want to share state between different /// threads, a shared object should be used, e.g. `Arc`. Application /// state does not need to be `Send` or `Sync`. + /// + /// ```rust + /// use std::cell::Cell; + /// use actix_web::{web, State, App}; + /// + /// struct MyState { + /// counter: Cell, + /// } + /// + /// fn index(state: State) { + /// state.counter.set(state.counter.get() + 1); + /// } + /// + /// fn main() { + /// let app = App::new() + /// .state(MyState{ counter: Cell::new(0) }) + /// .resource( + /// "/index.html", + /// |r| r.route(web::get().to(index))); + /// } + /// ``` pub fn state(mut self, state: S) -> Self { self.state.push(Box::new(State::new(state))); self diff --git a/src/extractor.rs b/src/extractor.rs index 04dfb81a..ea7681b0 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -938,66 +938,21 @@ impl

FromRequest

for () { } } +#[rustfmt::skip] +mod m { + use super::*; + tuple_from_req!(TupleFromRequest1, (0, A)); tuple_from_req!(TupleFromRequest2, (0, A), (1, B)); tuple_from_req!(TupleFromRequest3, (0, A), (1, B), (2, C)); tuple_from_req!(TupleFromRequest4, (0, A), (1, B), (2, C), (3, D)); tuple_from_req!(TupleFromRequest5, (0, A), (1, B), (2, C), (3, D), (4, E)); -tuple_from_req!( - TupleFromRequest6, - (0, A), - (1, B), - (2, C), - (3, D), - (4, E), - (5, F) -); -tuple_from_req!( - TupleFromRequest7, - (0, A), - (1, B), - (2, C), - (3, D), - (4, E), - (5, F), - (6, G) -); -tuple_from_req!( - TupleFromRequest8, - (0, A), - (1, B), - (2, C), - (3, D), - (4, E), - (5, F), - (6, G), - (7, H) -); -tuple_from_req!( - TupleFromRequest9, - (0, A), - (1, B), - (2, C), - (3, D), - (4, E), - (5, F), - (6, G), - (7, H), - (8, I) -); -tuple_from_req!( - TupleFromRequest10, - (0, A), - (1, B), - (2, C), - (3, D), - (4, E), - (5, F), - (6, G), - (7, H), - (8, I), - (9, J) -); +tuple_from_req!(TupleFromRequest6, (0, A), (1, B), (2, C), (3, D), (4, E), (5, F)); +tuple_from_req!(TupleFromRequest7, (0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G)); +tuple_from_req!(TupleFromRequest8, (0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G), (7, H)); +tuple_from_req!(TupleFromRequest9, (0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G), (7, H), (8, I)); +tuple_from_req!(TupleFromRequest10, (0, A), (1, B), (2, C), (3, D), (4, E), (5, F), (6, G), (7, H), (8, I), (9, J)); +} #[cfg(test)] mod tests {