os_id/thread/
mod.rs

1//! Thread id module
2
3use core::{cmp, hash, fmt};
4
5#[cfg(windows)]
6mod win32;
7#[cfg(windows)]
8pub use win32::*;
9#[cfg(unix)]
10mod unix;
11#[cfg(unix)]
12pub use unix::*;
13#[cfg(all(not(unix), not(windows)))]
14mod no_os;
15#[cfg(all(not(unix), not(windows)))]
16pub use no_os::*;
17
18#[repr(transparent)]
19#[derive(Copy, Clone, Debug)]
20///Thread identifier.
21pub struct ThreadId {
22    id: RawId,
23}
24
25impl ThreadId {
26    #[inline]
27    ///Gets current thread id
28    pub fn current() -> Self {
29        Self {
30            id: get_raw_id(),
31        }
32    }
33
34    #[inline]
35    ///Access Raw identifier.
36    pub const fn as_raw(&self) -> RawId {
37        self.id
38    }
39}
40
41impl cmp::Eq for ThreadId {}
42
43impl cmp::PartialEq<ThreadId> for ThreadId {
44    #[inline(always)]
45    fn eq(&self, other: &ThreadId) -> bool {
46        raw_thread_eq(self.id, other.id)
47    }
48}
49
50impl hash::Hash for ThreadId {
51    fn hash<H: hash::Hasher>(&self, state: &mut H) {
52        self.id.hash(state);
53    }
54}
55
56impl fmt::Display for ThreadId {
57    #[inline]
58    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59        fmt::Display::fmt(&self.id, f)
60    }
61}
62
63impl fmt::LowerHex for ThreadId {
64    #[inline]
65    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66        fmt::LowerHex::fmt(&self.id, f)
67    }
68}
69
70impl fmt::UpperHex for ThreadId {
71    #[inline]
72    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73        fmt::UpperHex::fmt(&self.id, f)
74    }
75}
76
77impl fmt::Octal for ThreadId {
78    #[inline]
79    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80        fmt::Octal::fmt(&self.id, f)
81    }
82}