33//! This module contains the `Future` trait and a number of adaptors for this
44//! trait. See the crate docs, and the docs for `Future`, for full detail.
55
6+ use core:: result;
7+
68// Primitive futures
7- mod done;
89mod empty;
9- mod failed ;
10- mod finished ;
10+ # [ path = "err.rs" ] // remove when deprecated reexports are gone
11+ mod err_ ;
1112mod lazy;
12- pub use self :: done:: { done, Done } ;
13+ #[ path = "ok.rs" ]
14+ mod ok_;
15+ #[ path = "result.rs" ]
16+ mod result_;
1317pub 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 } ;
1619pub 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 } ;
1735
1836// combinators
1937mod and_then;
@@ -220,7 +238,7 @@ pub trait Future {
220238 /// This function does not attempt to catch panics. If the `poll` function
221239 /// panics, panics will be propagated to the caller.
222240 #[ cfg( feature = "use_std" ) ]
223- fn wait ( self ) -> Result < Self :: Item , Self :: Error >
241+ fn wait ( self ) -> result :: Result < Self :: Item , Self :: Error >
224242 where Self : Sized
225243 {
226244 :: executor:: spawn ( self ) . wait_future ( )
@@ -239,14 +257,14 @@ pub trait Future {
239257 /// ```
240258 /// use futures::future::*;
241259 ///
242- /// let a: BoxFuture<i32, i32> = done (Ok(1)).boxed();
260+ /// let a: BoxFuture<i32, i32> = result (Ok(1)).boxed();
243261 /// ```
244262 #[ cfg( feature = "use_std" ) ]
245- fn boxed ( self ) -> BoxFuture < Self :: Item , Self :: Error >
263+ fn boxed ( self ) -> BoxFuture < Self :: Item , Self :: Error >
246264 where Self : Sized + Send + ' static
247265 {
248- :: std:: boxed:: Box :: new ( self )
249- }
266+ :: std:: boxed:: Box :: new ( self )
267+ }
250268
251269 /// Map this future's result to a different type, returning a new future of
252270 /// the resulting type.
@@ -268,7 +286,7 @@ pub trait Future {
268286 /// ```
269287 /// use futures::future::*;
270288 ///
271- /// let future_of_1 = finished ::<u32, u32>(1);
289+ /// let future_of_1 = ok ::<u32, u32>(1);
272290 /// let future_of_4 = future_of_1.map(|x| x + 3);
273291 /// ```
274292 fn map < F , U > ( self , f : F ) -> Map < Self , F >
@@ -297,7 +315,7 @@ pub trait Future {
297315 /// ```
298316 /// use futures::future::*;
299317 ///
300- /// let future_of_err_1 = failed ::<u32, u32>(1);
318+ /// let future_of_err_1 = err ::<u32, u32>(1);
301319 /// let future_of_err_4 = future_of_err_1.map_err(|x| x + 3);
302320 /// ```
303321 fn map_err < F , E > ( self , f : F ) -> MapErr < Self , F >
@@ -331,21 +349,21 @@ pub trait Future {
331349 /// ```
332350 /// use futures::future::*;
333351 ///
334- /// let future_of_1 = finished ::<u32, u32>(1);
352+ /// let future_of_1 = ok ::<u32, u32>(1);
335353 /// let future_of_4 = future_of_1.then(|x| {
336354 /// x.map(|y| y + 3)
337355 /// });
338356 ///
339- /// let future_of_err_1 = failed ::<u32, u32>(1);
357+ /// let future_of_err_1 = err ::<u32, u32>(1);
340358 /// let future_of_4 = future_of_err_1.then(|x| {
341359 /// match x {
342360 /// Ok(_) => panic!("expected an error"),
343- /// Err(y) => finished ::<u32, u32>(y + 3),
361+ /// Err(y) => ok ::<u32, u32>(y + 3),
344362 /// }
345363 /// });
346364 /// ```
347365 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 ,
349367 B : IntoFuture ,
350368 Self : Sized ,
351369 {
@@ -374,13 +392,13 @@ pub trait Future {
374392 /// ```
375393 /// use futures::future::*;
376394 ///
377- /// let future_of_1 = finished ::<u32, u32>(1);
395+ /// let future_of_1 = ok ::<u32, u32>(1);
378396 /// let future_of_4 = future_of_1.and_then(|x| {
379397 /// Ok(x + 3)
380398 /// });
381399 ///
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> {
384402 /// panic!("should not be called in case of an error");
385403 /// });
386404 /// ```
@@ -414,13 +432,13 @@ pub trait Future {
414432 /// ```
415433 /// use futures::future::*;
416434 ///
417- /// let future_of_err_1 = failed ::<u32, u32>(1);
435+ /// let future_of_err_1 = err ::<u32, u32>(1);
418436 /// let future_of_4 = future_of_err_1.or_else(|x| -> Result<u32, u32> {
419437 /// Ok(x + 3)
420438 /// });
421439 ///
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> {
424442 /// panic!("should not be called in case of success");
425443 /// });
426444 /// ```
@@ -455,7 +473,7 @@ pub trait Future {
455473 /// a.select(b).then(|res| {
456474 /// match res {
457475 /// Ok((a, b)) => b.map(move |b| (a, b)).boxed(),
458- /// Err((a, _)) => failed (a).boxed(),
476+ /// Err((a, _)) => err (a).boxed(),
459477 /// }
460478 /// }).boxed()
461479 /// }
@@ -490,8 +508,8 @@ pub trait Future {
490508 /// ```
491509 /// use futures::future::*;
492510 ///
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);
495513 /// let pair = a.join(b);
496514 ///
497515 /// pair.map(|(a, b)| {
@@ -552,12 +570,12 @@ pub trait Future {
552570 /// use futures::stream::Stream;
553571 /// use futures::future::*;
554572 ///
555- /// let future = finished ::<_, bool>(17);
573+ /// let future = ok ::<_, bool>(17);
556574 /// let mut stream = future.into_stream();
557575 /// assert_eq!(Ok(Async::Ready(Some(17))), stream.poll());
558576 /// assert_eq!(Ok(Async::Ready(None)), stream.poll());
559577 ///
560- /// let future = failed ::<bool, _>(19);
578+ /// let future = err ::<bool, _>(19);
561579 /// let mut stream = future.into_stream();
562580 /// assert_eq!(Err(19), stream.poll());
563581 /// assert_eq!(Ok(Async::Ready(None)), stream.poll());
@@ -587,7 +605,7 @@ pub trait Future {
587605 /// ```
588606 /// use futures::future::*;
589607 ///
590- /// let future_of_a_future = finished ::<_, u32>(finished ::<u32, u32>(1));
608+ /// let future_of_a_future = ok ::<_, u32>(ok ::<u32, u32>(1));
591609 /// let future_of_1 = future_of_a_future.flatten();
592610 /// ```
593611 fn flatten ( self ) -> Flatten < Self >
@@ -619,7 +637,7 @@ pub trait Future {
619637 /// use futures::future::*;
620638 ///
621639 /// 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));
623641 ///
624642 /// let stream = future_of_a_stream.flatten_stream();
625643 ///
@@ -659,14 +677,14 @@ pub trait Future {
659677 /// use futures::Async;
660678 /// use futures::future::*;
661679 ///
662- /// let mut future = finished ::<i32, u32>(2);
680+ /// let mut future = ok ::<i32, u32>(2);
663681 /// assert_eq!(future.poll(), Ok(Async::Ready(2)));
664682 ///
665683 /// // Normally, a call such as this would panic:
666684 /// //future.poll();
667685 ///
668686 /// // 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();
670688 /// assert_eq!(future.poll(), Ok(Async::Ready(2)));
671689 /// assert_eq!(future.poll(), Ok(Async::NotReady));
672690 /// ```
@@ -694,12 +712,12 @@ pub trait Future {
694712 /// ```rust
695713 /// use futures::future::*;
696714 ///
697- /// let mut future = finished ::<i32, u32>(2);
715+ /// let mut future = ok ::<i32, u32>(2);
698716 /// assert!(future.catch_unwind().wait().is_ok());
699717 ///
700718 /// let mut future = lazy(|| {
701719 /// panic!();
702- /// finished ::<i32, u32>(2)
720+ /// ok ::<i32, u32>(2)
703721 /// });
704722 /// assert!(future.catch_unwind().wait().is_err());
705723 /// ```
@@ -755,12 +773,12 @@ impl<F: Future> IntoFuture for F {
755773 }
756774}
757775
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 > ;
760778 type Item = T ;
761779 type Error = E ;
762780
763- fn into_future ( self ) -> Done < T , E > {
764- done ( self )
781+ fn into_future ( self ) -> FutureResult < T , E > {
782+ result ( self )
765783 }
766784}
0 commit comments