@@ -11,30 +11,27 @@ pub async fn map<Fut, U, F>(future: Fut, f: F) -> U
1111 where F : FnOnce ( Fut :: Output ) -> U ,
1212 Fut : Future ,
1313{
14- let future_result = await ! ( future) ;
15- f ( future_result)
14+ f ( future. await )
1615}
1716
1817pub async fn then < FutA , FutB , F > ( future : FutA , f : F ) -> FutB :: Output
1918 where F : FnOnce ( FutA :: Output ) -> FutB ,
2019 FutA : Future ,
2120 FutB : Future ,
2221{
23- let future_result = await ! ( future) ;
24- let new_future = f ( future_result) ;
25- await ! ( new_future)
22+ let new_future = f ( future. await ) ;
23+ new_future. await
2624}
2725
2826pub async fn and_then < FutA , FutB , F , T , U , E > ( future : FutA , f : F ) -> Result < U , E >
2927 where F : FnOnce ( T ) -> FutB ,
3028 FutA : Future < Output = Result < T , E > > ,
3129 FutB : Future < Output = Result < U , E > > ,
3230{
33- let future_result = await ! ( future) ;
34- match future_result {
31+ match future. await {
3532 Ok ( ok) => {
3633 let new_future = f ( ok) ;
37- await ! ( new_future)
34+ new_future. await
3835 } ,
3936 Err ( err) => Err ( err) ,
4037 }
@@ -45,12 +42,11 @@ pub async fn or_else<FutA, FutB, F, T, E, U>(future: FutA, f: F) -> Result<T, U>
4542 FutA : Future < Output = Result < T , E > > ,
4643 FutB : Future < Output = Result < T , U > > ,
4744{
48- let future_result = await ! ( future) ;
49- match future_result {
45+ match future. await {
5046 Ok ( ok) => Ok ( ok) ,
5147 Err ( err) => {
5248 let new_future = f ( err) ;
53- await ! ( new_future)
49+ new_future. await
5450 } ,
5551 }
5652}
@@ -59,31 +55,29 @@ pub async fn map_ok<Fut, F, T, U, E>(future: Fut, f: F) -> Result<U, E>
5955 where F : FnOnce ( T ) -> U ,
6056 Fut : Future < Output = Result < T , E > > ,
6157{
62- let future_result = await ! ( future) ;
63- future_result. map ( f)
58+ future. await . map ( f)
6459}
6560
6661pub async fn map_err < Fut , F , T , E , U > ( future : Fut , f : F ) -> Result < T , U >
6762 where F : FnOnce ( E ) -> U ,
6863 Fut : Future < Output = Result < T , E > > ,
6964{
70- let future_result = await ! ( future) ;
71- future_result. map_err ( f)
65+ future. await . map_err ( f)
7266}
7367
7468pub async fn flatten < FutA , FutB > ( future : FutA ) -> FutB :: Output
7569 where FutA : Future < Output = FutB > ,
7670 FutB : Future ,
7771{
78- let nested_future = await ! ( future) ;
79- await ! ( nested_future)
72+ let nested_future = future. await ;
73+ nested_future. await
8074}
8175
8276pub async fn inspect < Fut , F > ( future : Fut , f : F ) -> Fut :: Output
8377 where Fut : Future ,
8478 F : FnOnce ( & Fut :: Output ) ,
8579{
86- let future_result = await ! ( future) ;
80+ let future_result = future. await ;
8781 f ( & future_result) ;
8882 future_result
8983}
@@ -92,16 +86,14 @@ pub async fn err_into<Fut, T, E, U>(future: Fut) -> Result<T,U>
9286 where Fut : Future < Output = Result < T , E > > ,
9387 E : Into < U > ,
9488{
95- let future_result = await ! ( future) ;
96- future_result. map_err ( Into :: into)
89+ future. await . map_err ( Into :: into)
9790}
9891
9992pub async fn unwrap_or_else < Fut , T , E , F > ( future : Fut , f : F ) -> T
10093 where Fut : Future < Output = Result < T , E > > ,
10194 F : FnOnce ( E ) -> T ,
10295{
103- let future_result = await ! ( future) ;
104- future_result. unwrap_or_else ( f)
96+ future. await . unwrap_or_else ( f)
10597}
10698
10799pub fn flatten_stream < Fut , St , T > ( future : Fut ) -> impl Stream < Item = T >
@@ -112,13 +104,13 @@ pub fn flatten_stream<Fut, St, T>(future: Fut) -> impl Stream<Item = T>
112104 futures:: stream:: unfold ( ( Some ( future) , None ) , async move | ( future, stream) | {
113105 match ( future, stream) {
114106 ( Some ( future) , None ) => {
115- let stream = await ! ( future) ;
107+ let stream = future. await ;
116108 let mut stream = Box :: pin ( stream) ;
117- let item = await ! ( next( & mut stream) ) ;
109+ let item = next ( & mut stream) . await ;
118110 item. map ( |item| ( item, ( None , Some ( stream) ) ) )
119111 } ,
120112 ( None , Some ( mut stream) ) => {
121- let item = await ! ( next( & mut stream) ) ;
113+ let item = next ( & mut stream) . await ;
122114 item. map ( |item| ( item, ( None , Some ( stream) ) ) )
123115 } ,
124116 _ => unreachable ! ( )
@@ -131,7 +123,7 @@ pub fn into_stream<Fut>(future: Fut) -> impl Stream<Item = Fut::Output>
131123{
132124 futures:: stream:: unfold ( Some ( future) , async move |future| {
133125 if let Some ( future) = future {
134- let item = await ! ( future) ;
126+ let item = future. await ;
135127 Some ( ( item, ( None ) ) )
136128 } else {
137129 None
@@ -166,7 +158,7 @@ mod tests {
166158 fn test_ready ( ) {
167159 executor:: block_on ( async {
168160 let future = ready ( 1 ) ;
169- assert_eq ! ( await ! ( future) , 1 ) ;
161+ assert_eq ! ( future. await , 1 ) ;
170162 } ) ;
171163 }
172164
@@ -175,7 +167,7 @@ mod tests {
175167 executor:: block_on ( async {
176168 let future = ready ( 1 ) ;
177169 let new_future = map ( future, |x| x + 3 ) ;
178- assert_eq ! ( await ! ( new_future) , 4 ) ;
170+ assert_eq ! ( new_future. await , 4 ) ;
179171 } ) ;
180172 }
181173
@@ -184,7 +176,7 @@ mod tests {
184176 executor:: block_on ( async {
185177 let future = ready ( 1 ) ;
186178 let new_future = then ( future, |x| ready ( x + 3 ) ) ;
187- assert_eq ! ( await ! ( new_future) , 4 ) ;
179+ assert_eq ! ( new_future. await , 4 ) ;
188180 } ) ;
189181 }
190182
@@ -193,7 +185,7 @@ mod tests {
193185 executor:: block_on ( async {
194186 let future = ready ( Ok :: < i32 , i32 > ( 1 ) ) ;
195187 let new_future = and_then ( future, |x| ready ( Ok :: < i32 , i32 > ( x + 3 ) ) ) ;
196- assert_eq ! ( await ! ( new_future) , Ok ( 4 ) ) ;
188+ assert_eq ! ( new_future. await , Ok ( 4 ) ) ;
197189 } ) ;
198190 }
199191
@@ -202,7 +194,7 @@ mod tests {
202194 executor:: block_on ( async {
203195 let future = ready ( Err :: < i32 , i32 > ( 1 ) ) ;
204196 let new_future = or_else ( future, |x| ready ( Err :: < i32 , i32 > ( x + 3 ) ) ) ;
205- assert_eq ! ( await ! ( new_future) , Err ( 4 ) ) ;
197+ assert_eq ! ( new_future. await , Err ( 4 ) ) ;
206198 } ) ;
207199 }
208200
@@ -211,7 +203,7 @@ mod tests {
211203 executor:: block_on ( async {
212204 let future = ready ( Ok :: < i32 , i32 > ( 1 ) ) ;
213205 let new_future = map_ok ( future, |x| x + 3 ) ;
214- assert_eq ! ( await ! ( new_future) , Ok ( 4 ) ) ;
206+ assert_eq ! ( new_future. await , Ok ( 4 ) ) ;
215207 } ) ;
216208 }
217209
@@ -220,7 +212,7 @@ mod tests {
220212 executor:: block_on ( async {
221213 let future = ready ( Err :: < i32 , i32 > ( 1 ) ) ;
222214 let new_future = map_err ( future, |x| x + 3 ) ;
223- assert_eq ! ( await ! ( new_future) , Err ( 4 ) ) ;
215+ assert_eq ! ( new_future. await , Err ( 4 ) ) ;
224216 } ) ;
225217 }
226218
@@ -229,7 +221,7 @@ mod tests {
229221 executor:: block_on ( async {
230222 let nested_future = ready ( ready ( 1 ) ) ;
231223 let future = flatten ( nested_future) ;
232- assert_eq ! ( await ! ( future) , 1 ) ;
224+ assert_eq ! ( future. await , 1 ) ;
233225 } ) ;
234226 }
235227
@@ -238,7 +230,7 @@ mod tests {
238230 executor:: block_on ( async {
239231 let future = ready ( 1 ) ;
240232 let new_future = inspect ( future, |& x| assert_eq ! ( x, 1 ) ) ;
241- assert_eq ! ( await ! ( new_future) , 1 ) ;
233+ assert_eq ! ( new_future. await , 1 ) ;
242234 } ) ;
243235 }
244236
@@ -248,7 +240,7 @@ mod tests {
248240 let future_err_u8 = ready ( Err :: < ( ) , u8 > ( 1 ) ) ;
249241 let future_err_i32 = err_into :: < _ , _ , _ , i32 > ( future_err_u8) ;
250242
251- assert_eq ! ( await ! ( future_err_i32) , Err :: <( ) , i32 >( 1 ) ) ;
243+ assert_eq ! ( future_err_i32. await , Err :: <( ) , i32 >( 1 ) ) ;
252244 } ) ;
253245 }
254246
@@ -257,7 +249,7 @@ mod tests {
257249 executor:: block_on ( async {
258250 let future = ready ( Err :: < ( ) , & str > ( "Boom!" ) ) ;
259251 let new_future = unwrap_or_else ( future, |_| ( ) ) ;
260- assert_eq ! ( await ! ( new_future) , ( ) ) ;
252+ assert_eq ! ( new_future. await , ( ) ) ;
261253 } ) ;
262254 }
263255
@@ -269,7 +261,7 @@ mod tests {
269261 let future_of_a_stream = ready ( iter ( stream_items) ) ;
270262
271263 let stream = flatten_stream ( future_of_a_stream) ;
272- let list: Vec < _ > = await ! ( collect( stream) ) ;
264+ let list: Vec < _ > = collect ( stream) . await ;
273265 assert_eq ! ( list, vec![ 17 , 18 , 19 ] ) ;
274266 } ) ;
275267 }
@@ -280,7 +272,7 @@ mod tests {
280272 executor:: block_on ( async {
281273 let future = ready ( 17 ) ;
282274 let stream = into_stream ( future) ;
283- let collected: Vec < _ > = await ! ( collect( stream) ) ;
275+ let collected: Vec < _ > = collect ( stream) . await ;
284276 assert_eq ! ( collected, vec![ 17 ] ) ;
285277 } ) ;
286278 }
@@ -293,7 +285,7 @@ mod tests {
293285 } ;
294286
295287 let read_future = poll_fn ( read_line) ;
296- assert_eq ! ( await ! ( read_future) , "Hello, World!" . to_owned( ) ) ;
288+ assert_eq ! ( read_future. await , "Hello, World!" . to_owned( ) ) ;
297289 } ) ;
298290 }
299291
0 commit comments