use std::fmt;
use std::str::FromStr;
use nix::unistd;
use serde::Deserialize;
use serde::Serialize;
#[derive(
PartialEq, // Silly protection from rustfmt disagreements.
Debug,
Eq,
Clone,
Copy,
Hash,
PartialOrd,
Ord,
Serialize,
Deserialize,
Default,
)]
pub struct DetPid(i32);
impl fmt::Display for DetPid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
#[cfg(any())]
impl From<reverie_syscalls::Pid> for DetPid {
fn from(p: reverie_syscalls::Pid) -> Self {
DetPid(p.into())
}
}
impl From<unistd::Pid> for DetPid {
fn from(p: unistd::Pid) -> Self {
DetPid(p.into())
}
}
#[allow(clippy::from_over_into)]
impl Into<unistd::Pid> for DetPid {
fn into(self) -> unistd::Pid {
unistd::Pid::from_raw(self.0)
}
}
impl DetPid {
pub const fn from_raw(pid: i32) -> DetPid {
DetPid(pid)
}
pub fn as_raw(&self) -> i32 {
self.0
}
}
impl FromStr for DetPid {
type Err = <i32 as FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from_raw(s.parse::<i32>()?))
}
}
pub type DetTid = DetPid;