os_id/process/
mod.rs

1//! Process 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///Process identifier.
21pub struct ProcessId {
22    id: RawId,
23}
24
25impl ProcessId {
26    #[inline]
27    ///Gets current process 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::PartialEq<ProcessId> for ProcessId {
42    #[inline]
43    fn eq(&self, other: &ProcessId) -> bool {
44        self.id == other.id
45    }
46}
47
48impl cmp::Eq for ProcessId {}
49
50impl hash::Hash for ProcessId {
51    #[inline]
52    fn hash<H: hash::Hasher>(&self, state: &mut H) {
53        self.id.hash(state);
54    }
55}
56
57impl fmt::Display for ProcessId {
58    #[inline]
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        fmt::Display::fmt(&self.id, f)
61    }
62}
63
64impl fmt::LowerHex for ProcessId {
65    #[inline]
66    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67        fmt::LowerHex::fmt(&self.id, f)
68    }
69}
70
71impl fmt::UpperHex for ProcessId {
72    #[inline]
73    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74        fmt::UpperHex::fmt(&self.id, f)
75    }
76}
77
78impl fmt::Octal for ProcessId {
79    #[inline]
80    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81        fmt::Octal::fmt(&self.id, f)
82    }
83}