1616
1717use fmt;
1818use ptr:: NonNull ;
19+ use future:: Future ;
20+ use mem:: PinMut ;
1921
2022/// Indicates whether a value is available or if the current task has been
2123/// scheduled to receive a wakeup instead.
@@ -455,8 +457,8 @@ pub trait Executor {
455457/// `Box<Future<Output = ()> + Send>`.
456458pub struct TaskObj {
457459 ptr : * mut ( ) ,
458- poll : unsafe fn ( * mut ( ) , & mut Context ) -> Poll < ( ) > ,
459- drop : unsafe fn ( * mut ( ) ) ,
460+ poll_fn : unsafe fn ( * mut ( ) , & mut Context ) -> Poll < ( ) > ,
461+ drop_fn : unsafe fn ( * mut ( ) ) ,
460462}
461463
462464impl fmt:: Debug for TaskObj {
@@ -467,7 +469,6 @@ impl fmt::Debug for TaskObj {
467469}
468470
469471unsafe impl Send for TaskObj { }
470- unsafe impl Sync for TaskObj { }
471472
472473/// A custom implementation of a task trait object for `TaskObj`, providing
473474/// a hand-rolled vtable.
@@ -478,7 +479,7 @@ unsafe impl Sync for TaskObj {}
478479/// The implementor must guarantee that it is safe to call `poll` repeatedly (in
479480/// a non-concurrent fashion) with the result of `into_raw` until `drop` is
480481/// called.
481- pub unsafe trait UnsafePoll : Send + ' static {
482+ pub unsafe trait UnsafeTask : Send + ' static {
482483 /// Convert a owned instance into a (conceptually owned) void pointer.
483484 fn into_raw ( self ) -> * mut ( ) ;
484485
@@ -504,30 +505,30 @@ pub unsafe trait UnsafePoll: Send + 'static {
504505impl TaskObj {
505506 /// Create a `TaskObj` from a custom trait object representation.
506507 #[ inline]
507- pub fn from_poll_task < T : UnsafePoll > ( t : T ) -> TaskObj {
508+ pub fn new < T : UnsafeTask > ( t : T ) -> TaskObj {
508509 TaskObj {
509510 ptr : t. into_raw ( ) ,
510- poll : T :: poll,
511- drop : T :: drop,
511+ poll_fn : T :: poll,
512+ drop_fn : T :: drop,
512513 }
513514 }
515+ }
516+
517+ impl Future for TaskObj {
518+ type Output = ( ) ;
514519
515- /// Poll the task.
516- ///
517- /// The semantics here are identical to that for futures, but unlike
518- /// futures only an `&mut self` reference is needed here.
519520 #[ inline]
520- pub fn poll_task ( & mut self , cx : & mut Context ) -> Poll < ( ) > {
521+ fn poll ( self : PinMut < Self > , cx : & mut Context ) -> Poll < ( ) > {
521522 unsafe {
522- ( self . poll ) ( self . ptr , cx)
523+ ( self . poll_fn ) ( self . ptr , cx)
523524 }
524525 }
525526}
526527
527528impl Drop for TaskObj {
528529 fn drop ( & mut self ) {
529530 unsafe {
530- ( self . drop ) ( self . ptr )
531+ ( self . drop_fn ) ( self . ptr )
531532 }
532533 }
533534}
0 commit comments