]> git.proxmox.com Git - rustc.git/blob - vendor/sysinfo/src/apple/process.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / vendor / sysinfo / src / apple / process.rs
1 // Take a look at the license at the top of the repository in the LICENSE file.
2
3 use std::fmt;
4
5 pub use crate::sys::inner::process::*;
6 use crate::ProcessStatus;
7
8 #[doc(hidden)]
9 impl From<u32> for ProcessStatus {
10 fn from(status: u32) -> ProcessStatus {
11 match status {
12 1 => ProcessStatus::Idle,
13 2 => ProcessStatus::Run,
14 3 => ProcessStatus::Sleep,
15 4 => ProcessStatus::Stop,
16 5 => ProcessStatus::Zombie,
17 x => ProcessStatus::Unknown(x),
18 }
19 }
20 }
21
22 impl fmt::Display for ProcessStatus {
23 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24 f.write_str(match *self {
25 ProcessStatus::Idle => "Idle",
26 ProcessStatus::Run => "Runnable",
27 ProcessStatus::Sleep => "Sleeping",
28 ProcessStatus::Stop => "Stopped",
29 ProcessStatus::Zombie => "Zombie",
30 _ => "Unknown",
31 })
32 }
33 }
34
35 /// Enum describing the different status of a thread.
36 #[derive(Clone, Debug, PartialEq, Eq)]
37 pub enum ThreadStatus {
38 /// Thread is running normally.
39 Running,
40 /// Thread is stopped.
41 Stopped,
42 /// Thread is waiting normally.
43 Waiting,
44 /// Thread is in an uninterruptible wait
45 Uninterruptible,
46 /// Thread is halted at a clean point.
47 Halted,
48 /// Unknown.
49 Unknown(i32),
50 }
51
52 impl From<i32> for ThreadStatus {
53 fn from(status: i32) -> ThreadStatus {
54 match status {
55 1 => ThreadStatus::Running,
56 2 => ThreadStatus::Stopped,
57 3 => ThreadStatus::Waiting,
58 4 => ThreadStatus::Uninterruptible,
59 5 => ThreadStatus::Halted,
60 x => ThreadStatus::Unknown(x),
61 }
62 }
63 }
64
65 impl ThreadStatus {
66 /// Used to display `ThreadStatus`.
67 pub fn to_string(&self) -> &str {
68 match *self {
69 ThreadStatus::Running => "Running",
70 ThreadStatus::Stopped => "Stopped",
71 ThreadStatus::Waiting => "Waiting",
72 ThreadStatus::Uninterruptible => "Uninterruptible",
73 ThreadStatus::Halted => "Halted",
74 ThreadStatus::Unknown(_) => "Unknown",
75 }
76 }
77 }
78
79 impl fmt::Display for ThreadStatus {
80 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81 write!(f, "{}", self.to_string())
82 }
83 }