1#[cfg(feature = "component")]
4pub(crate) mod component;
5#[cfg(feature = "disk")]
6pub(crate) mod disk;
7#[cfg(feature = "gpu")]
8pub(crate) mod gpu;
9#[cfg(any(feature = "system", feature = "disk"))]
10pub(crate) mod impl_get_set;
11#[cfg(feature = "network")]
12pub(crate) mod network;
13#[cfg(feature = "system")]
14pub(crate) mod system;
15#[cfg(feature = "user")]
16pub(crate) mod user;
17
18#[cfg_attr(not(all(feature = "system", feature = "disk")), doc = "```ignore")]
23#[cfg(any(feature = "disk", feature = "system"))]
49#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd)]
50pub struct DiskUsage {
51 pub total_written_bytes: u64,
53 pub written_bytes: u64,
55 pub total_read_bytes: u64,
57 pub read_bytes: u64,
59}
60
61macro_rules! xid {
62 ($(#[$outer:meta])+ $name:ident, $type:ty $(, $trait:ty)?) => {
63 #[cfg(any(feature = "system", feature = "user"))]
64 $(#[$outer])+
65 #[repr(transparent)]
66 #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
67 pub struct $name(pub(crate) $type);
68
69 #[cfg(any(feature = "system", feature = "user"))]
70 impl std::ops::Deref for $name {
71 type Target = $type;
72
73 fn deref(&self) -> &Self::Target {
74 &self.0
75 }
76 }
77
78 $(
79 #[cfg(any(feature = "system", feature = "user"))]
80 impl TryFrom<usize> for $name {
81 type Error = <$type as TryFrom<usize>>::Error;
82
83 fn try_from(t: usize) -> Result<Self, <$type as TryFrom<usize>>::Error> {
84 Ok(Self(<$type>::try_from(t)?))
85 }
86 }
87
88 #[cfg(any(feature = "system", feature = "user"))]
89 impl $trait for $name {
90 type Err = <$type as $trait>::Err;
91
92 fn from_str(t: &str) -> Result<Self, <$type as $trait>::Err> {
93 Ok(Self(<$type>::from_str(t)?))
94 }
95 }
96 )?
97 };
98}
99
100macro_rules! uid {
101 ($type:ty$(, $trait:ty)?) => {
102 xid!(
103 Uid,
105 $type
106 $(, $trait)?
107 );
108 };
109}
110
111macro_rules! gid {
112 ($type:ty) => {
113 xid!(
114 #[derive(Copy)]
116 Gid,
117 $type,
118 std::str::FromStr
119 );
120 };
121}
122
123cfg_select! {
124 all(
125 not(feature = "unknown-ci"),
126 any(
127 target_os = "freebsd",
128 target_os = "netbsd",
129 target_os = "linux",
130 target_os = "android",
131 target_os = "macos",
132 target_os = "ios",
133 )
134 ) => {
135 uid!(libc::uid_t, std::str::FromStr);
136 gid!(libc::gid_t);
137 }
138 windows => {
139 uid!(crate::windows::Sid);
140 gid!(u32);
141 #[cfg(any(feature = "system", feature = "user"))]
143 impl std::str::FromStr for Uid {
144 type Err = <crate::windows::Sid as std::str::FromStr>::Err;
145
146 fn from_str(t: &str) -> Result<Self, Self::Err> {
147 Ok(Self(t.parse()?))
148 }
149 }
150 }
151 _ => {
152 uid!(u32, std::str::FromStr);
153 gid!(u32);
154 }
155}