11mod test_utils;
22use test_utils:: ServerTestingExt ;
3- use tide:: RequestState ;
3+ use tide:: { Request , RequestState } ;
44
55#[ async_std:: test]
66async fn nested ( ) -> tide:: Result < ( ) > {
@@ -19,7 +19,7 @@ async fn nested() -> tide::Result<()> {
1919
2020#[ async_std:: test]
2121async fn nested_middleware ( ) -> tide:: Result < ( ) > {
22- let echo_path = |req : tide :: Request | async move { Ok ( req. url ( ) . path ( ) . to_string ( ) ) } ;
22+ let echo_path = |req : Request | async move { Ok ( req. url ( ) . path ( ) . to_string ( ) ) } ;
2323 let mut app = tide:: new ( ) ;
2424 let mut inner_app = tide:: new ( ) ;
2525 inner_app. with ( tide:: utils:: After ( |mut res : tide:: Response | async move {
@@ -48,12 +48,15 @@ async fn nested_middleware() -> tide::Result<()> {
4848 Ok ( ( ) )
4949}
5050
51+ #[ derive( Clone ) ]
52+ struct Num ( i32 ) ;
53+
5154#[ async_std:: test]
5255async fn nested_with_different_state ( ) -> tide:: Result < ( ) > {
5356 let mut outer = tide:: new ( ) ;
54- let mut inner = tide:: with_state ( 42 ) ;
55- inner. at ( "/" ) . get ( |req : tide :: Request < i32 > | async move {
56- let num = req. state ( ) ;
57+ let mut inner = tide:: with_state ( Num ( 42 ) ) ;
58+ inner. at ( "/" ) . get ( |req : Request | async move {
59+ let num = req. state ( ) . 0 ;
5760 Ok ( format ! ( "the number is {}" , num) )
5861 } ) ;
5962 outer. at ( "/" ) . get ( |_| async { Ok ( "Hello, world!" ) } ) ;
@@ -64,8 +67,8 @@ async fn nested_with_different_state() -> tide::Result<()> {
6467 Ok ( ( ) )
6568}
6669
67- impl RequestState < i32 > for tide :: Request {
68- fn state ( & self ) -> & i32 {
69- self . ext :: < i32 > ( ) . unwrap ( )
70+ impl RequestState < Num > for Request {
71+ fn state ( & self ) -> & Num {
72+ self . ext :: < Num > ( ) . unwrap ( )
7073 }
7174}
0 commit comments