heim_host/os/
linux.rs

1//! Linux-specific extensions.
2
3use std::net::IpAddr;
4
5use crate::Pid;
6
7/// Linux-specific extensions for [User].
8///
9/// In Linux user information is provided by `utmpx` (see `man utmpx(5)`),
10/// trait methods are representing fields of this struct.
11///
12/// [User]: ../../struct.User.html
13pub trait UserExt {
14    /// Returns the `Pid` of login process.
15    fn pid(&self) -> Pid;
16
17    /// Returns the tty or pseudo-tty name associated with user.
18    fn terminal(&self) -> &str;
19
20    /// Returns the terminal identifier.
21    fn id(&self) -> &str;
22
23    /// Returns the hostname for remote login.
24    fn hostname(&self) -> &str;
25
26    /// Returns the IP address of remote host.
27    fn address(&self) -> Option<IpAddr>;
28
29    /// Returns the Session ID.
30    fn session_id(&self) -> i32;
31}
32
33#[cfg(target_os = "linux")]
34impl UserExt for crate::User {
35    fn pid(&self) -> Pid {
36        self.as_ref().pid()
37    }
38
39    fn terminal(&self) -> &str {
40        self.as_ref().terminal()
41    }
42
43    fn id(&self) -> &str {
44        self.as_ref().id()
45    }
46
47    fn hostname(&self) -> &str {
48        self.as_ref().hostname()
49    }
50
51    fn address(&self) -> Option<IpAddr> {
52        self.as_ref().address()
53    }
54
55    fn session_id(&self) -> i32 {
56        self.as_ref().session_id()
57    }
58}