]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/task/context.rs
Auto merge of #54174 - parched:park, r=alexcrichton
[rust.git] / src / libcore / task / context.rs
index 1fc975cb178819d9584c8c3604ea36fab5b93a08..5a29c8528ef3a0801c9a467a4f1ec21d5abd267c 100644 (file)
@@ -13,7 +13,7 @@
             issue = "50547")]
 
 use fmt;
-use super::{Executor, Waker, LocalWaker};
+use super::{Spawn, Waker, LocalWaker};
 
 /// Information about the currently-running task.
 ///
@@ -21,7 +21,7 @@
 /// when performing a single `poll` step on a task.
 pub struct Context<'a> {
     local_waker: &'a LocalWaker,
-    executor: &'a mut dyn Executor,
+    spawner: &'a mut dyn Spawn,
 }
 
 impl<'a> fmt::Debug for Context<'a> {
@@ -32,13 +32,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl<'a> Context<'a> {
-    /// Create a new task `Context` with the provided `local_waker`, `waker`, and `executor`.
+    /// Create a new task `Context` with the provided `local_waker`, `waker`,
+    /// and `spawner`.
     #[inline]
-    pub fn new(local_waker: &'a LocalWaker, executor: &'a mut dyn Executor) -> Context<'a> {
-        Context {
-            local_waker,
-            executor,
-        }
+    pub fn new(
+        local_waker: &'a LocalWaker,
+        spawner: &'a mut dyn Spawn,
+    ) -> Context<'a> {
+        Context { local_waker, spawner }
     }
 
     /// Get the `LocalWaker` associated with the current task.
@@ -53,40 +54,45 @@ pub fn waker(&self) -> &'a Waker {
         unsafe { &*(self.local_waker as *const LocalWaker as *const Waker) }
     }
 
-    /// Get the default executor associated with this task.
+    /// Get the spawner associated with this task.
     ///
     /// This method is useful primarily if you want to explicitly handle
     /// spawn failures.
     #[inline]
-    pub fn executor(&mut self) -> &mut dyn Executor {
-        self.executor
+    pub fn spawner(&mut self) -> &mut dyn Spawn {
+        self.spawner
     }
 
-    /// Produce a context like the current one, but using the given waker instead.
+    /// Produce a context like the current one, but using the given waker
+    /// instead.
     ///
     /// This advanced method is primarily used when building "internal
     /// schedulers" within a task, where you want to provide some customized
     /// wakeup logic.
     #[inline]
-    pub fn with_waker<'b>(&'b mut self, local_waker: &'b LocalWaker) -> Context<'b> {
+    pub fn with_waker<'b>(
+        &'b mut self,
+        local_waker: &'b LocalWaker,
+    ) -> Context<'b> {
         Context {
             local_waker,
-            executor: self.executor,
+            spawner: self.spawner,
         }
     }
 
-    /// Produce a context like the current one, but using the given executor
+    /// Produce a context like the current one, but using the given spawner
     /// instead.
     ///
     /// This advanced method is primarily used when building "internal
     /// schedulers" within a task.
     #[inline]
-    pub fn with_executor<'b, E>(&'b mut self, executor: &'b mut E) -> Context<'b>
-        where E: Executor
-    {
+    pub fn with_spawner<'b, Sp: Spawn>(
+        &'b mut self,
+        spawner: &'b mut Sp,
+    ) -> Context<'b> {
         Context {
             local_waker: self.local_waker,
-            executor: executor,
+            spawner,
         }
     }
 }