From e128fc879f4e69b62919ea2549bfcfea77ab99a2 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 14 Jan 2020 12:05:04 +0100 Subject: [PATCH] sys: Add TryFrom 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 variant. Signed-off-by: Wolfgang Bumiller --- proxmox-sys/src/linux/procfs.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proxmox-sys/src/linux/procfs.rs b/proxmox-sys/src/linux/procfs.rs index 23d73a76..f4b52eab 100644 --- a/proxmox-sys/src/linux/procfs.rs +++ b/proxmox-sys/src/linux/procfs.rs @@ -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 for PidStat { + type Error = Error; + + fn try_from(pid: Pid) -> Result { + 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 {