]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/task/wake.rs
Remove spawning from task::Context
[rust.git] / src / libcore / task / wake.rs
index 321b432d3f4307b7c29681caddda75b5453bf2c3..651db6356ba07e93bd727adb9ed81932a3492fc8 100644 (file)
@@ -42,7 +42,7 @@ impl Waker {
     /// `Arc` type and the safe `Wake` trait.
     #[inline]
     pub unsafe fn new(inner: NonNull<dyn UnsafeWake>) -> Self {
-        Waker { inner: inner }
+        Waker { inner }
     }
 
     /// Wake up the task associated with this `Waker`.
@@ -120,7 +120,16 @@ impl LocalWaker {
     /// on the current thread.
     #[inline]
     pub unsafe fn new(inner: NonNull<dyn UnsafeWake>) -> Self {
-        LocalWaker { inner: inner }
+        LocalWaker { inner }
+    }
+
+    /// Converts this `LocalWaker` into a `Waker`.
+    ///
+    /// `Waker` is nearly identical to `LocalWaker`, but is threadsafe
+    /// (implements `Send` and `Sync`).
+    #[inline]
+    pub fn into_waker(self) -> Waker {
+        self.into()
     }
 
     /// Wake up the task associated with this `LocalWaker`.
@@ -159,7 +168,9 @@ pub fn will_wake_nonlocal(&self, other: &Waker) -> bool {
 impl From<LocalWaker> for Waker {
     #[inline]
     fn from(local_waker: LocalWaker) -> Self {
-        Waker { inner: local_waker.inner }
+        let inner = local_waker.inner;
+        mem::forget(local_waker);
+        Waker { inner }
     }
 }