Skip to content

Commit d75d40f

Browse files
committed
Implement fmt::Display for Pid, Uid, Gid
Closes bytecodealliance#1439
1 parent cb01fbe commit d75d40f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/pid.rs

+7-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;
@@ -87,6 +87,12 @@ impl Pid {
8787
}
8888
}
8989

90+
impl fmt::Display for Pid {
91+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92+
write!(f, "{}", self.0)
93+
}
94+
}
95+
9096
#[cfg(test)]
9197
mod tests {
9298
use super::*;

src/ugid.rs

+14
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,18 @@ impl Gid {
8688
}
8789
}
8890

91+
impl fmt::Display for Uid {
92+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93+
write!(f, "{}", self.0)
94+
}
95+
}
96+
97+
impl fmt::Display for Gid {
98+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99+
write!(f, "{}", self.0)
100+
}
101+
}
102+
89103
// Return the raw value of the IDs. In case of `None` it returns `!0` since it
90104
// has the same bit pattern as `-1` indicating no change to the owner/group ID.
91105
pub(crate) fn translate_fchown_args(

0 commit comments

Comments
 (0)