| 1 | use std::fmt; |
| 2 | use std::num::TryFromIntError; |
| 3 | |
| 4 | /// Used as a wrapper for the process ID |
| 5 | #[derive(Clone, Copy, PartialEq, Eq)] |
| 6 | pub struct Pid(pub(crate) u32); |
| 7 | |
| 8 | impl From<u32> for Pid { |
| 9 | fn from(value: u32) -> Self { |
| 10 | Self(value) |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | impl TryFrom<i32> for Pid { |
| 15 | type Error = TryFromIntError; |
| 16 | |
| 17 | fn try_from(value: i32) -> Result<Self, Self::Error> { |
| 18 | Ok(Self(value.try_into()?)) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | impl fmt::Display for Pid { |
| 23 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 24 | write!(f, "{}", self.0) |
| 25 | } |
| 26 | } |