Skip to content

Commit dd2fe86

Browse files
rusty-snakeevilpie
andcommitted
Implement more formatter for Pid, Uid, Gid
Closes bytecodealliance#1439 Co-authored-by: Tom Schuster <[email protected]>
1 parent cd95201 commit dd2fe86

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

src/pid.rs

+37-1
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;
@@ -94,6 +94,42 @@ impl Pid {
9494
}
9595
}
9696

97+
impl fmt::Display for Pid {
98+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99+
self.0.fmt(f)
100+
}
101+
}
102+
impl fmt::Binary for Pid {
103+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104+
self.0.fmt(f)
105+
}
106+
}
107+
impl fmt::Octal for Pid {
108+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
109+
self.0.fmt(f)
110+
}
111+
}
112+
impl fmt::LowerHex for Pid {
113+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114+
self.0.fmt(f)
115+
}
116+
}
117+
impl fmt::UpperHex for Pid {
118+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119+
self.0.fmt(f)
120+
}
121+
}
122+
impl fmt::LowerExp for Pid {
123+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124+
self.0.fmt(f)
125+
}
126+
}
127+
impl fmt::UpperExp for Pid {
128+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129+
self.0.fmt(f)
130+
}
131+
}
132+
97133
#[cfg(test)]
98134
mod tests {
99135
use super::*;

src/ugid.rs

+74
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)