diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs index d5953c20b..aea5af8ca 100644 --- a/tokio/src/runtime/blocking/pool.rs +++ b/tokio/src/runtime/blocking/pool.rs @@ -7,7 +7,7 @@ use crate::runtime::blocking::{shutdown, BlockingTask}; use crate::runtime::builder::ThreadNameFn; use crate::runtime::context; use crate::runtime::task::{self, JoinHandle}; -use crate::runtime::{Builder, Callback, ToHandle}; +use crate::runtime::{Builder, Callback, Handle}; use std::collections::{HashMap, VecDeque}; use std::fmt; @@ -242,7 +242,7 @@ impl fmt::Debug for BlockingPool { impl Spawner { #[track_caller] - pub(crate) fn spawn_blocking(&self, rt: &dyn ToHandle, func: F) -> JoinHandle + pub(crate) fn spawn_blocking(&self, rt: &Handle, func: F) -> JoinHandle where F: FnOnce() -> R + Send + 'static, R: Send + 'static, @@ -270,7 +270,7 @@ impl Spawner { all(loom, not(test)), // the function is covered by loom tests test ), allow(dead_code))] - pub(crate) fn spawn_mandatory_blocking(&self, rt: &dyn ToHandle, func: F) -> Option> + pub(crate) fn spawn_mandatory_blocking(&self, rt: &Handle, func: F) -> Option> where F: FnOnce() -> R + Send + 'static, R: Send + 'static, @@ -305,7 +305,7 @@ impl Spawner { func: F, is_mandatory: Mandatory, name: Option<&str>, - rt: &dyn ToHandle, + rt: &Handle, ) -> (JoinHandle, Result<(), SpawnError>) where F: FnOnce() -> R + Send + 'static, @@ -337,7 +337,7 @@ impl Spawner { (handle, spawned) } - fn spawn_task(&self, task: Task, rt: &dyn ToHandle) -> Result<(), SpawnError> { + fn spawn_task(&self, task: Task, rt: &Handle) -> Result<(), SpawnError> { let mut shared = self.inner.shared.lock(); if shared.shutdown { @@ -400,7 +400,7 @@ impl Spawner { fn spawn_thread( &self, shutdown_tx: shutdown::Sender, - rt: &dyn ToHandle, + rt: &Handle, id: usize, ) -> std::io::Result> { let mut builder = thread::Builder::new().name((self.inner.thread_name)()); @@ -409,7 +409,7 @@ impl Spawner { builder = builder.stack_size(stack_size); } - let rt = rt.to_handle(); + let rt = rt.clone(); builder.spawn(move || { // Only the reference should be moved into the closure diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs index 4675d7af9..9c0752db0 100644 --- a/tokio/src/runtime/handle.rs +++ b/tokio/src/runtime/handle.rs @@ -54,11 +54,6 @@ pub(crate) struct HandleInner { pub(crate) blocking_spawner: blocking::Spawner, } -/// Create a new runtime handle. -pub(crate) trait ToHandle { - fn to_handle(&self) -> Handle; -} - /// Runtime context guard. /// /// Returned by [`Runtime::enter`] and [`Handle::enter`], the context guard exits @@ -319,12 +314,6 @@ impl Handle { } } -impl ToHandle for Handle { - fn to_handle(&self) -> Handle { - self.clone() - } -} - cfg_metrics! { use crate::runtime::RuntimeMetrics; diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index 36238e376..79cf11c35 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -222,7 +222,7 @@ cfg_rt! { mod handle; pub use handle::{EnterGuard, Handle, TryCurrentError}; - pub(crate) use handle::{HandleInner, ToHandle}; + pub(crate) use handle::HandleInner; mod spawner; use self::spawner::Spawner; diff --git a/tokio/src/runtime/scheduler/multi_thread/worker.rs b/tokio/src/runtime/scheduler/multi_thread/worker.rs index 44615d262..6952d9efe 100644 --- a/tokio/src/runtime/scheduler/multi_thread/worker.rs +++ b/tokio/src/runtime/scheduler/multi_thread/worker.rs @@ -854,19 +854,6 @@ impl Shared { } } -impl crate::runtime::ToHandle for Arc { - fn to_handle(&self) -> crate::runtime::Handle { - use crate::runtime::scheduler::multi_thread::Spawner; - use crate::runtime::{self, Handle}; - - Handle { - spawner: runtime::Spawner::MultiThread(Spawner { - shared: self.clone(), - }), - } - } -} - cfg_metrics! { impl Shared { pub(super) fn injection_queue_depth(&self) -> usize {