@@ -11,30 +11,27 @@ pub async fn map<Fut, U, F>(future: Fut, f: F) -> U
11
11
where F : FnOnce ( Fut :: Output ) -> U ,
12
12
Fut : Future ,
13
13
{
14
- let future_result = await ! ( future) ;
15
- f ( future_result)
14
+ f ( future. await )
16
15
}
17
16
18
17
pub async fn then < FutA , FutB , F > ( future : FutA , f : F ) -> FutB :: Output
19
18
where F : FnOnce ( FutA :: Output ) -> FutB ,
20
19
FutA : Future ,
21
20
FutB : Future ,
22
21
{
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
26
24
}
27
25
28
26
pub async fn and_then < FutA , FutB , F , T , U , E > ( future : FutA , f : F ) -> Result < U , E >
29
27
where F : FnOnce ( T ) -> FutB ,
30
28
FutA : Future < Output = Result < T , E > > ,
31
29
FutB : Future < Output = Result < U , E > > ,
32
30
{
33
- let future_result = await ! ( future) ;
34
- match future_result {
31
+ match future. await {
35
32
Ok ( ok) => {
36
33
let new_future = f ( ok) ;
37
- await ! ( new_future)
34
+ new_future. await
38
35
} ,
39
36
Err ( err) => Err ( err) ,
40
37
}
@@ -45,12 +42,11 @@ pub async fn or_else<FutA, FutB, F, T, E, U>(future: FutA, f: F) -> Result<T, U>
45
42
FutA : Future < Output = Result < T , E > > ,
46
43
FutB : Future < Output = Result < T , U > > ,
47
44
{
48
- let future_result = await ! ( future) ;
49
- match future_result {
45
+ match future. await {
50
46
Ok ( ok) => Ok ( ok) ,
51
47
Err ( err) => {
52
48
let new_future = f ( err) ;
53
- await ! ( new_future)
49
+ new_future. await
54
50
} ,
55
51
}
56
52
}
@@ -59,31 +55,29 @@ pub async fn map_ok<Fut, F, T, U, E>(future: Fut, f: F) -> Result<U, E>
59
55
where F : FnOnce ( T ) -> U ,
60
56
Fut : Future < Output = Result < T , E > > ,
61
57
{
62
- let future_result = await ! ( future) ;
63
- future_result. map ( f)
58
+ future. await . map ( f)
64
59
}
65
60
66
61
pub async fn map_err < Fut , F , T , E , U > ( future : Fut , f : F ) -> Result < T , U >
67
62
where F : FnOnce ( E ) -> U ,
68
63
Fut : Future < Output = Result < T , E > > ,
69
64
{
70
- let future_result = await ! ( future) ;
71
- future_result. map_err ( f)
65
+ future. await . map_err ( f)
72
66
}
73
67
74
68
pub async fn flatten < FutA , FutB > ( future : FutA ) -> FutB :: Output
75
69
where FutA : Future < Output = FutB > ,
76
70
FutB : Future ,
77
71
{
78
- let nested_future = await ! ( future) ;
79
- await ! ( nested_future)
72
+ let nested_future = future. await ;
73
+ nested_future. await
80
74
}
81
75
82
76
pub async fn inspect < Fut , F > ( future : Fut , f : F ) -> Fut :: Output
83
77
where Fut : Future ,
84
78
F : FnOnce ( & Fut :: Output ) ,
85
79
{
86
- let future_result = await ! ( future) ;
80
+ let future_result = future. await ;
87
81
f ( & future_result) ;
88
82
future_result
89
83
}
@@ -92,16 +86,14 @@ pub async fn err_into<Fut, T, E, U>(future: Fut) -> Result<T,U>
92
86
where Fut : Future < Output = Result < T , E > > ,
93
87
E : Into < U > ,
94
88
{
95
- let future_result = await ! ( future) ;
96
- future_result. map_err ( Into :: into)
89
+ future. await . map_err ( Into :: into)
97
90
}
98
91
99
92
pub async fn unwrap_or_else < Fut , T , E , F > ( future : Fut , f : F ) -> T
100
93
where Fut : Future < Output = Result < T , E > > ,
101
94
F : FnOnce ( E ) -> T ,
102
95
{
103
- let future_result = await ! ( future) ;
104
- future_result. unwrap_or_else ( f)
96
+ future. await . unwrap_or_else ( f)
105
97
}
106
98
107
99
pub 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>
112
104
futures:: stream:: unfold ( ( Some ( future) , None ) , async move | ( future, stream) | {
113
105
match ( future, stream) {
114
106
( Some ( future) , None ) => {
115
- let stream = await ! ( future) ;
107
+ let stream = future. await ;
116
108
let mut stream = Box :: pin ( stream) ;
117
- let item = await ! ( next( & mut stream) ) ;
109
+ let item = next ( & mut stream) . await ;
118
110
item. map ( |item| ( item, ( None , Some ( stream) ) ) )
119
111
} ,
120
112
( None , Some ( mut stream) ) => {
121
- let item = await ! ( next( & mut stream) ) ;
113
+ let item = next ( & mut stream) . await ;
122
114
item. map ( |item| ( item, ( None , Some ( stream) ) ) )
123
115
} ,
124
116
_ => unreachable ! ( )
@@ -131,7 +123,7 @@ pub fn into_stream<Fut>(future: Fut) -> impl Stream<Item = Fut::Output>
131
123
{
132
124
futures:: stream:: unfold ( Some ( future) , async move |future| {
133
125
if let Some ( future) = future {
134
- let item = await ! ( future) ;
126
+ let item = future. await ;
135
127
Some ( ( item, ( None ) ) )
136
128
} else {
137
129
None
@@ -166,7 +158,7 @@ mod tests {
166
158
fn test_ready ( ) {
167
159
executor:: block_on ( async {
168
160
let future = ready ( 1 ) ;
169
- assert_eq ! ( await ! ( future) , 1 ) ;
161
+ assert_eq ! ( future. await , 1 ) ;
170
162
} ) ;
171
163
}
172
164
@@ -175,7 +167,7 @@ mod tests {
175
167
executor:: block_on ( async {
176
168
let future = ready ( 1 ) ;
177
169
let new_future = map ( future, |x| x + 3 ) ;
178
- assert_eq ! ( await ! ( new_future) , 4 ) ;
170
+ assert_eq ! ( new_future. await , 4 ) ;
179
171
} ) ;
180
172
}
181
173
@@ -184,7 +176,7 @@ mod tests {
184
176
executor:: block_on ( async {
185
177
let future = ready ( 1 ) ;
186
178
let new_future = then ( future, |x| ready ( x + 3 ) ) ;
187
- assert_eq ! ( await ! ( new_future) , 4 ) ;
179
+ assert_eq ! ( new_future. await , 4 ) ;
188
180
} ) ;
189
181
}
190
182
@@ -193,7 +185,7 @@ mod tests {
193
185
executor:: block_on ( async {
194
186
let future = ready ( Ok :: < i32 , i32 > ( 1 ) ) ;
195
187
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 ) ) ;
197
189
} ) ;
198
190
}
199
191
@@ -202,7 +194,7 @@ mod tests {
202
194
executor:: block_on ( async {
203
195
let future = ready ( Err :: < i32 , i32 > ( 1 ) ) ;
204
196
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 ) ) ;
206
198
} ) ;
207
199
}
208
200
@@ -211,7 +203,7 @@ mod tests {
211
203
executor:: block_on ( async {
212
204
let future = ready ( Ok :: < i32 , i32 > ( 1 ) ) ;
213
205
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 ) ) ;
215
207
} ) ;
216
208
}
217
209
@@ -220,7 +212,7 @@ mod tests {
220
212
executor:: block_on ( async {
221
213
let future = ready ( Err :: < i32 , i32 > ( 1 ) ) ;
222
214
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 ) ) ;
224
216
} ) ;
225
217
}
226
218
@@ -229,7 +221,7 @@ mod tests {
229
221
executor:: block_on ( async {
230
222
let nested_future = ready ( ready ( 1 ) ) ;
231
223
let future = flatten ( nested_future) ;
232
- assert_eq ! ( await ! ( future) , 1 ) ;
224
+ assert_eq ! ( future. await , 1 ) ;
233
225
} ) ;
234
226
}
235
227
@@ -238,7 +230,7 @@ mod tests {
238
230
executor:: block_on ( async {
239
231
let future = ready ( 1 ) ;
240
232
let new_future = inspect ( future, |& x| assert_eq ! ( x, 1 ) ) ;
241
- assert_eq ! ( await ! ( new_future) , 1 ) ;
233
+ assert_eq ! ( new_future. await , 1 ) ;
242
234
} ) ;
243
235
}
244
236
@@ -248,7 +240,7 @@ mod tests {
248
240
let future_err_u8 = ready ( Err :: < ( ) , u8 > ( 1 ) ) ;
249
241
let future_err_i32 = err_into :: < _ , _ , _ , i32 > ( future_err_u8) ;
250
242
251
- assert_eq ! ( await ! ( future_err_i32) , Err :: <( ) , i32 >( 1 ) ) ;
243
+ assert_eq ! ( future_err_i32. await , Err :: <( ) , i32 >( 1 ) ) ;
252
244
} ) ;
253
245
}
254
246
@@ -257,7 +249,7 @@ mod tests {
257
249
executor:: block_on ( async {
258
250
let future = ready ( Err :: < ( ) , & str > ( "Boom!" ) ) ;
259
251
let new_future = unwrap_or_else ( future, |_| ( ) ) ;
260
- assert_eq ! ( await ! ( new_future) , ( ) ) ;
252
+ assert_eq ! ( new_future. await , ( ) ) ;
261
253
} ) ;
262
254
}
263
255
@@ -269,7 +261,7 @@ mod tests {
269
261
let future_of_a_stream = ready ( iter ( stream_items) ) ;
270
262
271
263
let stream = flatten_stream ( future_of_a_stream) ;
272
- let list: Vec < _ > = await ! ( collect( stream) ) ;
264
+ let list: Vec < _ > = collect ( stream) . await ;
273
265
assert_eq ! ( list, vec![ 17 , 18 , 19 ] ) ;
274
266
} ) ;
275
267
}
@@ -280,7 +272,7 @@ mod tests {
280
272
executor:: block_on ( async {
281
273
let future = ready ( 17 ) ;
282
274
let stream = into_stream ( future) ;
283
- let collected: Vec < _ > = await ! ( collect( stream) ) ;
275
+ let collected: Vec < _ > = collect ( stream) . await ;
284
276
assert_eq ! ( collected, vec![ 17 ] ) ;
285
277
} ) ;
286
278
}
@@ -293,7 +285,7 @@ mod tests {
293
285
} ;
294
286
295
287
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( ) ) ;
297
289
} ) ;
298
290
}
299
291
0 commit comments