Skip to content

Commit 92466d9

Browse files
rusty-snakeevilpie
andauthored
Implement more formatter for Pid, Uid, Gid (#1449)
Closes #1439 Co-authored-by: Tom Schuster <evilpies@gmail.com>
1 parent e5b793b commit 92466d9

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

src/pid.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![allow(unsafe_code)]
44

5-
use core::num::NonZeroI32;
5+
use core::{fmt, num::NonZeroI32};
66

77
/// A process identifier as a raw integer.
88
pub type RawPid = i32;
@@ -102,6 +102,42 @@ impl Pid {
102102
}
103103
}
104104

105+
impl fmt::Display for Pid {
106+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107+
self.0.fmt(f)
108+
}
109+
}
110+
impl fmt::Binary for Pid {
111+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112+
self.0.fmt(f)
113+
}
114+
}
115+
impl fmt::Octal for Pid {
116+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117+
self.0.fmt(f)
118+
}
119+
}
120+
impl fmt::LowerHex for Pid {
121+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122+
self.0.fmt(f)
123+
}
124+
}
125+
impl fmt::UpperHex for Pid {
126+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127+
self.0.fmt(f)
128+
}
129+
}
130+
impl fmt::LowerExp for Pid {
131+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
132+
self.0.fmt(f)
133+
}
134+
}
135+
impl fmt::UpperExp for Pid {
136+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
137+
self.0.fmt(f)
138+
}
139+
}
140+
105141
#[cfg(test)]
106142
mod tests {
107143
use super::*;

src/ugid.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! User and Group ID types.
22
3+
use core::fmt;
4+
35
use crate::backend::c;
46
use crate::ffi;
57

@@ -86,6 +88,78 @@ impl Gid {
8688
}
8789
}
8890

91+
impl fmt::Display for Uid {
92+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93+
self.0.fmt(f)
94+
}
95+
}
96+
impl fmt::Binary for Uid {
97+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98+
self.0.fmt(f)
99+
}
100+
}
101+
impl fmt::Octal for Uid {
102+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103+
self.0.fmt(f)
104+
}
105+
}
106+
impl fmt::LowerHex for Uid {
107+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108+
self.0.fmt(f)
109+
}
110+
}
111+
impl fmt::UpperHex for Uid {
112+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113+
self.0.fmt(f)
114+
}
115+
}
116+
impl fmt::LowerExp for Uid {
117+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118+
self.0.fmt(f)
119+
}
120+
}
121+
impl fmt::UpperExp for Uid {
122+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123+
self.0.fmt(f)
124+
}
125+
}
126+
127+
impl fmt::Display for Gid {
128+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129+
self.0.fmt(f)
130+
}
131+
}
132+
impl fmt::Binary for Gid {
133+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134+
self.0.fmt(f)
135+
}
136+
}
137+
impl fmt::Octal for Gid {
138+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139+
self.0.fmt(f)
140+
}
141+
}
142+
impl fmt::LowerHex for Gid {
143+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144+
self.0.fmt(f)
145+
}
146+
}
147+
impl fmt::UpperHex for Gid {
148+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149+
self.0.fmt(f)
150+
}
151+
}
152+
impl fmt::LowerExp for Gid {
153+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
154+
self.0.fmt(f)
155+
}
156+
}
157+
impl fmt::UpperExp for Gid {
158+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159+
self.0.fmt(f)
160+
}
161+
}
162+
89163
// Return the raw value of the IDs. In case of `None` it returns `!0` since it
90164
// has the same bit pattern as `-1` indicating no change to the owner/group ID.
91165
pub(crate) fn translate_fchown_args(

0 commit comments

Comments
 (0)