diff options
Diffstat (limited to 'vendor/sysinfo-0.26.7/src/apple/process.rs')
-rw-r--r-- | vendor/sysinfo-0.26.7/src/apple/process.rs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/sysinfo-0.26.7/src/apple/process.rs b/vendor/sysinfo-0.26.7/src/apple/process.rs new file mode 100644 index 000000000..e0f005bdc --- /dev/null +++ b/vendor/sysinfo-0.26.7/src/apple/process.rs @@ -0,0 +1,83 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use std::fmt; + +pub use crate::sys::inner::process::*; +use crate::ProcessStatus; + +#[doc(hidden)] +impl From<u32> for ProcessStatus { + fn from(status: u32) -> ProcessStatus { + match status { + 1 => ProcessStatus::Idle, + 2 => ProcessStatus::Run, + 3 => ProcessStatus::Sleep, + 4 => ProcessStatus::Stop, + 5 => ProcessStatus::Zombie, + x => ProcessStatus::Unknown(x), + } + } +} + +impl fmt::Display for ProcessStatus { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(match *self { + ProcessStatus::Idle => "Idle", + ProcessStatus::Run => "Runnable", + ProcessStatus::Sleep => "Sleeping", + ProcessStatus::Stop => "Stopped", + ProcessStatus::Zombie => "Zombie", + _ => "Unknown", + }) + } +} + +/// Enum describing the different status of a thread. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum ThreadStatus { + /// Thread is running normally. + Running, + /// Thread is stopped. + Stopped, + /// Thread is waiting normally. + Waiting, + /// Thread is in an uninterruptible wait + Uninterruptible, + /// Thread is halted at a clean point. + Halted, + /// Unknown. + Unknown(i32), +} + +impl From<i32> for ThreadStatus { + fn from(status: i32) -> ThreadStatus { + match status { + 1 => ThreadStatus::Running, + 2 => ThreadStatus::Stopped, + 3 => ThreadStatus::Waiting, + 4 => ThreadStatus::Uninterruptible, + 5 => ThreadStatus::Halted, + x => ThreadStatus::Unknown(x), + } + } +} + +impl ThreadStatus { + /// Used to display `ThreadStatus`. + pub fn to_string(&self) -> &str { + match *self { + ThreadStatus::Running => "Running", + ThreadStatus::Stopped => "Stopped", + ThreadStatus::Waiting => "Waiting", + ThreadStatus::Uninterruptible => "Uninterruptible", + ThreadStatus::Halted => "Halted", + ThreadStatus::Unknown(_) => "Unknown", + } + } +} + +impl fmt::Display for ThreadStatus { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.to_string()) + } +} |