From 231a3a69f9a191c88b94a9ff141865f9a8d0bf84 Mon Sep 17 00:00:00 2001 From: Qi Date: Tue, 16 Dec 2025 19:02:09 +0800 Subject: [PATCH] task: stabilize the `LocalSet::id()` (#7776) Signed-off-by: ADD-SP --- tokio/src/task/local.rs | 44 ++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index e80307f3b..c1764300b 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -1,7 +1,6 @@ //! Runs `!Send` futures on the current thread. use crate::loom::cell::UnsafeCell; use crate::loom::sync::{Arc, Mutex}; -#[cfg(tokio_unstable)] use crate::runtime; use crate::runtime::task::{ self, JoinHandle, LocalOwnedTasks, SpawnLocation, Task, TaskHarnessScheduleHooks, @@ -844,6 +843,25 @@ impl LocalSet { Err(_access_error) => (f.take().unwrap())(), } } + + /// Returns the [`Id`] of the current [`LocalSet`] runtime. + /// + /// # Examples + /// + /// ```rust + /// use tokio::task; + /// + /// # #[tokio::main(flavor = "current_thread")] + /// # async fn main() { + /// let local_set = task::LocalSet::new(); + /// println!("Local set id: {}", local_set.id()); + /// # } + /// ``` + /// + /// [`Id`]: struct@crate::runtime::Id + pub fn id(&self) -> runtime::Id { + runtime::Id::new(self.context.shared.local_state.owned.id) + } } cfg_unstable! { @@ -914,30 +932,6 @@ cfg_unstable! { .unhandled_panic = behavior; self } - - /// Returns the [`Id`] of the current `LocalSet` runtime. - /// - /// # Examples - /// - /// ```rust - /// use tokio::task; - /// - /// # #[tokio::main(flavor = "current_thread")] - /// # async fn main() { - /// let local_set = task::LocalSet::new(); - /// println!("Local set id: {}", local_set.id()); - /// # } - /// ``` - /// - /// **Note**: This is an [unstable API][unstable]. The public API of this type - /// may break in 1.x releases. See [the documentation on unstable - /// features][unstable] for details. - /// - /// [unstable]: crate#unstable-features - /// [`Id`]: struct@crate::runtime::Id - pub fn id(&self) -> runtime::Id { - runtime::Id::new(self.context.shared.local_state.owned.id) - } } }