From 776b3d64b18c24bbf9d64bcdfa4b8ae032e78af0 Mon Sep 17 00:00:00 2001 From: aaronjeline Date: Thu, 10 Jul 2025 22:04:56 -0400 Subject: [PATCH] task: opens `Id::as_u64` to clients Allows clients to observe the contents of Task IDs, with no guarantees on contents. Fixes: #7430 --- tokio/src/runtime/task/id.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tokio/src/runtime/task/id.rs b/tokio/src/runtime/task/id.rs index 63d01700bfd..7615a246959 100644 --- a/tokio/src/runtime/task/id.rs +++ b/tokio/src/runtime/task/id.rs @@ -74,7 +74,21 @@ impl Id { } } - pub(crate) fn as_u64(&self) -> u64 { + /// Retrieves the underlying [`u64`] for this [`Id`] + /// There are no guarantees about the order or contents of this [`u64`]. + /// + /// # Example + /// + /// ``` + /// # tokio_test::block_on(async { + /// let handle = tokio::spawn(async { + /// let id = tokio::task::id(); + /// let id_as_u64 : u64 = id.as_u64(); + /// }); + /// handle.await.unwrap(); + /// # }); + /// ``` + pub fn as_u64(&self) -> u64 { self.0.get() } }