mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-02 17:44:31 +00:00
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:
parent
42a155668e
commit
e128fc879f
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user