3
3
//! This module contains the `Future` trait and a number of adaptors for this
4
4
//! trait. See the crate docs, and the docs for `Future`, for full detail.
5
5
6
+ use core:: result;
7
+
6
8
// Primitive futures
7
- mod done;
8
9
mod empty;
9
- mod failed ;
10
- mod finished ;
10
+ # [ path = "err.rs" ] // remove when deprecated reexports are gone
11
+ mod err_ ;
11
12
mod lazy;
12
- pub use self :: done:: { done, Done } ;
13
+ #[ path = "ok.rs" ]
14
+ mod ok_;
15
+ #[ path = "result.rs" ]
16
+ mod result_;
13
17
pub use self :: empty:: { empty, Empty } ;
14
- pub use self :: failed:: { failed, Failed } ;
15
- pub use self :: finished:: { finished, Finished } ;
18
+ pub use self :: err_:: { err, Err } ;
16
19
pub use self :: lazy:: { lazy, Lazy } ;
20
+ pub use self :: ok_:: { ok, Ok } ;
21
+ pub use self :: result_:: { result, FutureResult } ;
22
+
23
+ #[ doc( hidden) ]
24
+ #[ deprecated( since = "0.1.4" , note = "use `ok` instead" ) ]
25
+ #[ cfg( feature = "with-deprecated" ) ]
26
+ pub use self :: { ok as finished, Ok as Finished } ;
27
+ #[ doc( hidden) ]
28
+ #[ deprecated( since = "0.1.4" , note = "use `err` instead" ) ]
29
+ #[ cfg( feature = "with-deprecated" ) ]
30
+ pub use self :: { err as failed, Err as Failed } ;
31
+ #[ doc( hidden) ]
32
+ #[ deprecated( since = "0.1.4" , note = "use `result` instead" ) ]
33
+ #[ cfg( feature = "with-deprecated" ) ]
34
+ pub use self :: { result as done, FutureResult as Done } ;
17
35
18
36
// combinators
19
37
mod and_then;
@@ -220,7 +238,7 @@ pub trait Future {
220
238
/// This function does not attempt to catch panics. If the `poll` function
221
239
/// panics, panics will be propagated to the caller.
222
240
#[ cfg( feature = "use_std" ) ]
223
- fn wait ( self ) -> Result < Self :: Item , Self :: Error >
241
+ fn wait ( self ) -> result :: Result < Self :: Item , Self :: Error >
224
242
where Self : Sized
225
243
{
226
244
:: executor:: spawn ( self ) . wait_future ( )
@@ -239,14 +257,14 @@ pub trait Future {
239
257
/// ```
240
258
/// use futures::future::*;
241
259
///
242
- /// let a: BoxFuture<i32, i32> = done (Ok(1)).boxed();
260
+ /// let a: BoxFuture<i32, i32> = result (Ok(1)).boxed();
243
261
/// ```
244
262
#[ cfg( feature = "use_std" ) ]
245
- fn boxed ( self ) -> BoxFuture < Self :: Item , Self :: Error >
263
+ fn boxed ( self ) -> BoxFuture < Self :: Item , Self :: Error >
246
264
where Self : Sized + Send + ' static
247
265
{
248
- :: std:: boxed:: Box :: new ( self )
249
- }
266
+ :: std:: boxed:: Box :: new ( self )
267
+ }
250
268
251
269
/// Map this future's result to a different type, returning a new future of
252
270
/// the resulting type.
@@ -268,7 +286,7 @@ pub trait Future {
268
286
/// ```
269
287
/// use futures::future::*;
270
288
///
271
- /// let future_of_1 = finished ::<u32, u32>(1);
289
+ /// let future_of_1 = ok ::<u32, u32>(1);
272
290
/// let future_of_4 = future_of_1.map(|x| x + 3);
273
291
/// ```
274
292
fn map < F , U > ( self , f : F ) -> Map < Self , F >
@@ -297,7 +315,7 @@ pub trait Future {
297
315
/// ```
298
316
/// use futures::future::*;
299
317
///
300
- /// let future_of_err_1 = failed ::<u32, u32>(1);
318
+ /// let future_of_err_1 = err ::<u32, u32>(1);
301
319
/// let future_of_err_4 = future_of_err_1.map_err(|x| x + 3);
302
320
/// ```
303
321
fn map_err < F , E > ( self , f : F ) -> MapErr < Self , F >
@@ -331,21 +349,21 @@ pub trait Future {
331
349
/// ```
332
350
/// use futures::future::*;
333
351
///
334
- /// let future_of_1 = finished ::<u32, u32>(1);
352
+ /// let future_of_1 = ok ::<u32, u32>(1);
335
353
/// let future_of_4 = future_of_1.then(|x| {
336
354
/// x.map(|y| y + 3)
337
355
/// });
338
356
///
339
- /// let future_of_err_1 = failed ::<u32, u32>(1);
357
+ /// let future_of_err_1 = err ::<u32, u32>(1);
340
358
/// let future_of_4 = future_of_err_1.then(|x| {
341
359
/// match x {
342
360
/// Ok(_) => panic!("expected an error"),
343
- /// Err(y) => finished ::<u32, u32>(y + 3),
361
+ /// Err(y) => ok ::<u32, u32>(y + 3),
344
362
/// }
345
363
/// });
346
364
/// ```
347
365
fn then < F , B > ( self , f : F ) -> Then < Self , B , F >
348
- where F : FnOnce ( Result < Self :: Item , Self :: Error > ) -> B ,
366
+ where F : FnOnce ( result :: Result < Self :: Item , Self :: Error > ) -> B ,
349
367
B : IntoFuture ,
350
368
Self : Sized ,
351
369
{
@@ -374,13 +392,13 @@ pub trait Future {
374
392
/// ```
375
393
/// use futures::future::*;
376
394
///
377
- /// let future_of_1 = finished ::<u32, u32>(1);
395
+ /// let future_of_1 = ok ::<u32, u32>(1);
378
396
/// let future_of_4 = future_of_1.and_then(|x| {
379
397
/// Ok(x + 3)
380
398
/// });
381
399
///
382
- /// let future_of_err_1 = failed ::<u32, u32>(1);
383
- /// future_of_err_1.and_then(|_| -> Done <u32, u32> {
400
+ /// let future_of_err_1 = err ::<u32, u32>(1);
401
+ /// future_of_err_1.and_then(|_| -> Ok <u32, u32> {
384
402
/// panic!("should not be called in case of an error");
385
403
/// });
386
404
/// ```
@@ -414,13 +432,13 @@ pub trait Future {
414
432
/// ```
415
433
/// use futures::future::*;
416
434
///
417
- /// let future_of_err_1 = failed ::<u32, u32>(1);
435
+ /// let future_of_err_1 = err ::<u32, u32>(1);
418
436
/// let future_of_4 = future_of_err_1.or_else(|x| -> Result<u32, u32> {
419
437
/// Ok(x + 3)
420
438
/// });
421
439
///
422
- /// let future_of_1 = finished ::<u32, u32>(1);
423
- /// future_of_1.or_else(|_| -> Done <u32, u32> {
440
+ /// let future_of_1 = ok ::<u32, u32>(1);
441
+ /// future_of_1.or_else(|_| -> Ok <u32, u32> {
424
442
/// panic!("should not be called in case of success");
425
443
/// });
426
444
/// ```
@@ -455,7 +473,7 @@ pub trait Future {
455
473
/// a.select(b).then(|res| {
456
474
/// match res {
457
475
/// Ok((a, b)) => b.map(move |b| (a, b)).boxed(),
458
- /// Err((a, _)) => failed (a).boxed(),
476
+ /// Err((a, _)) => err (a).boxed(),
459
477
/// }
460
478
/// }).boxed()
461
479
/// }
@@ -490,8 +508,8 @@ pub trait Future {
490
508
/// ```
491
509
/// use futures::future::*;
492
510
///
493
- /// let a = finished ::<u32, u32>(1);
494
- /// let b = finished ::<u32, u32>(2);
511
+ /// let a = ok ::<u32, u32>(1);
512
+ /// let b = ok ::<u32, u32>(2);
495
513
/// let pair = a.join(b);
496
514
///
497
515
/// pair.map(|(a, b)| {
@@ -552,12 +570,12 @@ pub trait Future {
552
570
/// use futures::stream::Stream;
553
571
/// use futures::future::*;
554
572
///
555
- /// let future = finished ::<_, bool>(17);
573
+ /// let future = ok ::<_, bool>(17);
556
574
/// let mut stream = future.into_stream();
557
575
/// assert_eq!(Ok(Async::Ready(Some(17))), stream.poll());
558
576
/// assert_eq!(Ok(Async::Ready(None)), stream.poll());
559
577
///
560
- /// let future = failed ::<bool, _>(19);
578
+ /// let future = err ::<bool, _>(19);
561
579
/// let mut stream = future.into_stream();
562
580
/// assert_eq!(Err(19), stream.poll());
563
581
/// assert_eq!(Ok(Async::Ready(None)), stream.poll());
@@ -587,7 +605,7 @@ pub trait Future {
587
605
/// ```
588
606
/// use futures::future::*;
589
607
///
590
- /// let future_of_a_future = finished ::<_, u32>(finished ::<u32, u32>(1));
608
+ /// let future_of_a_future = ok ::<_, u32>(ok ::<u32, u32>(1));
591
609
/// let future_of_1 = future_of_a_future.flatten();
592
610
/// ```
593
611
fn flatten ( self ) -> Flatten < Self >
@@ -619,7 +637,7 @@ pub trait Future {
619
637
/// use futures::future::*;
620
638
///
621
639
/// let stream_items = vec![Ok(17), Err(true), Ok(19)];
622
- /// let future_of_a_stream = finished ::<_, bool>(stream::iter(stream_items));
640
+ /// let future_of_a_stream = ok ::<_, bool>(stream::iter(stream_items));
623
641
///
624
642
/// let stream = future_of_a_stream.flatten_stream();
625
643
///
@@ -659,14 +677,14 @@ pub trait Future {
659
677
/// use futures::Async;
660
678
/// use futures::future::*;
661
679
///
662
- /// let mut future = finished ::<i32, u32>(2);
680
+ /// let mut future = ok ::<i32, u32>(2);
663
681
/// assert_eq!(future.poll(), Ok(Async::Ready(2)));
664
682
///
665
683
/// // Normally, a call such as this would panic:
666
684
/// //future.poll();
667
685
///
668
686
/// // This, however, is guaranteed to not panic
669
- /// let mut future = finished ::<i32, u32>(2).fuse();
687
+ /// let mut future = ok ::<i32, u32>(2).fuse();
670
688
/// assert_eq!(future.poll(), Ok(Async::Ready(2)));
671
689
/// assert_eq!(future.poll(), Ok(Async::NotReady));
672
690
/// ```
@@ -694,12 +712,12 @@ pub trait Future {
694
712
/// ```rust
695
713
/// use futures::future::*;
696
714
///
697
- /// let mut future = finished ::<i32, u32>(2);
715
+ /// let mut future = ok ::<i32, u32>(2);
698
716
/// assert!(future.catch_unwind().wait().is_ok());
699
717
///
700
718
/// let mut future = lazy(|| {
701
719
/// panic!();
702
- /// finished ::<i32, u32>(2)
720
+ /// ok ::<i32, u32>(2)
703
721
/// });
704
722
/// assert!(future.catch_unwind().wait().is_err());
705
723
/// ```
@@ -755,12 +773,12 @@ impl<F: Future> IntoFuture for F {
755
773
}
756
774
}
757
775
758
- impl < T , E > IntoFuture for Result < T , E > {
759
- type Future = Done < T , E > ;
776
+ impl < T , E > IntoFuture for result :: Result < T , E > {
777
+ type Future = FutureResult < T , E > ;
760
778
type Item = T ;
761
779
type Error = E ;
762
780
763
- fn into_future ( self ) -> Done < T , E > {
764
- done ( self )
781
+ fn into_future ( self ) -> FutureResult < T , E > {
782
+ result ( self )
765
783
}
766
784
}
0 commit comments