sys: Add TryFrom<Pid> for PidStat

Since nix's Pid type is a strong type, we can add a TryFrom
implementation here as well.
This can later also have the equivalent TryFrom<PidFd>
variant.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-01-14 12:05:04 +01:00
parent 42a155668e
commit e128fc879f

View File

@ -1,4 +1,5 @@
use std::collections::HashSet;
use std::convert::TryFrom;
use std::fs::OpenOptions;
use std::io::{BufRead, BufReader};
use std::net::{Ipv4Addr, Ipv6Addr};
@ -118,6 +119,14 @@ impl PidStat {
}
}
impl TryFrom<Pid> for PidStat {
type Error = Error;
fn try_from(pid: Pid) -> Result<Self, Error> {
Self::read_for_pid(pid)
}
}
/// Read `/proc/PID/stat` for a pid.
#[deprecated(note = "use `PidStat::read_for_pid`")]
pub fn read_proc_pid_stat(pid: libc::pid_t) -> Result<PidStat, Error> {