1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::fmt;
use std::path::PathBuf;
use heim_common::prelude::*;
use crate::{sys, Pid, ProcessResult};
mod status;
pub use self::status::Status;
#[derive(heim_derive::ImplWrap)]
pub struct Process(sys::Process);
impl Process {
pub fn pid(&self) -> Pid {
self.as_ref().pid()
}
pub fn parent_pid(&self) -> impl Future<Output = ProcessResult<Pid>> {
self.as_ref().parent_pid()
}
pub fn name(&self) -> impl Future<Output = ProcessResult<String>> {
self.as_ref().name()
}
pub fn exe(&self) -> impl Future<Output = ProcessResult<PathBuf>> {
self.as_ref().exe()
}
pub fn status(&self) -> impl Future<Output = ProcessResult<Status>> {
self.as_ref().status()
}
}
impl fmt::Debug for Process {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Process").field("pid", &self.pid()).finish()
}
}
pub fn processes() -> impl Stream<Item = ProcessResult<Process>> {
sys::processes().map_ok(Into::into)
}