/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/id.rs
Line | Count | Source |
1 | | use std::fmt; |
2 | | use std::num::NonZeroU64; |
3 | | |
4 | | /// An opaque ID that uniquely identifies a runtime relative to all other currently |
5 | | /// running runtimes. |
6 | | /// |
7 | | /// # Notes |
8 | | /// |
9 | | /// - Runtime IDs are unique relative to other *currently running* runtimes. |
10 | | /// When a runtime completes, the same ID may be used for another runtime. |
11 | | /// - Runtime IDs are *not* sequential, and do not indicate the order in which |
12 | | /// runtimes are started or any other data. |
13 | | /// - The runtime ID of the currently running task can be obtained from the |
14 | | /// Handle. |
15 | | /// |
16 | | /// # Examples |
17 | | /// |
18 | | /// ``` |
19 | | /// # #[cfg(not(target_family = "wasm"))] |
20 | | /// # { |
21 | | /// use tokio::runtime::Handle; |
22 | | /// |
23 | | /// #[tokio::main(flavor = "multi_thread", worker_threads = 4)] |
24 | | /// async fn main() { |
25 | | /// println!("Current runtime id: {}", Handle::current().id()); |
26 | | /// } |
27 | | /// # } |
28 | | /// ``` |
29 | | #[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] |
30 | | pub struct Id(NonZeroU64); |
31 | | |
32 | | impl Id { |
33 | 0 | pub(crate) fn new(integer: impl Into<NonZeroU64>) -> Self { |
34 | 0 | Self(integer.into()) |
35 | 0 | } |
36 | | } |
37 | | |
38 | | impl fmt::Display for Id { |
39 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
40 | 0 | self.0.fmt(f) |
41 | 0 | } |
42 | | } |