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