@@ -2,25 +2,29 @@ use crate::future::Future;
22use crate :: pin:: Pin ;
33use crate :: task:: { Context , Poll } ;
44
5- /// A future that is immediately ready with a value.
6- ///
7- /// This `struct` is created by [`ready()`]. See its
8- /// documentation for more.
9- #[ stable( feature = "future_readiness_fns" , since = "1.48.0" ) ]
10- #[ derive( Debug , Clone ) ]
11- #[ must_use = "futures do nothing unless you `.await` or poll them" ]
12- pub struct Ready < T > ( Option < T > ) ;
5+ pin_project_lite:: pin_project! {
6+ /// A future that is immediately ready with a value.
7+ ///
8+ /// This `struct` is created by [`ready()`]. See its
9+ /// documentation for more.
10+ #[ stable( feature = "future_readiness_fns" , since = "1.48.0" ) ]
11+ #[ derive( Debug , Clone ) ]
12+ #[ must_use = "futures do nothing unless you `.await` or poll them" ]
13+ pub struct Ready <T > {
14+ inner: Option <T >,
15+ }
16+ }
1317
14- #[ stable( feature = "future_readiness_fns" , since = "1.48.0" ) ]
15- impl < T > Unpin for Ready < T > { }
18+ // #[stable(feature = "future_readiness_fns", since = "1.48.0")]
19+ // impl<T> Unpin for Ready<T> {}
1620
1721#[ stable( feature = "future_readiness_fns" , since = "1.48.0" ) ]
1822impl < T > Future for Ready < T > {
1923 type Output = T ;
2024
2125 #[ inline]
22- fn poll ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < T > {
23- Poll :: Ready ( self . 0 . take ( ) . expect ( "`Ready` polled after completion" ) )
26+ fn poll ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < T > {
27+ Poll :: Ready ( self . project ( ) . inner . take ( ) . expect ( "`Ready` polled after completion" ) )
2428 }
2529}
2630
@@ -44,7 +48,7 @@ impl<T> Ready<T> {
4448 #[ must_use]
4549 #[ inline]
4650 pub fn into_inner ( self ) -> T {
47- self . 0 . expect ( "Called `into_inner()` on `Ready` after completion" )
51+ self . inner . expect ( "Called `into_inner()` on `Ready` after completion" )
4852 }
4953}
5054
@@ -66,5 +70,5 @@ impl<T> Ready<T> {
6670/// ```
6771#[ stable( feature = "future_readiness_fns" , since = "1.48.0" ) ]
6872pub fn ready < T > ( t : T ) -> Ready < T > {
69- Ready ( Some ( t) )
73+ Ready { inner : Some ( t) }
7074}
0 commit comments