heim_host/
users.rs

1use std::fmt;
2
3use crate::sys;
4use heim_common::prelude::*;
5
6/// User currently connected to system.
7///
8/// See [os] module for OS-specific extensions.
9///
10/// [os]: ./os/index.html
11pub struct User(sys::User);
12
13wrap!(User, sys::User);
14
15impl User {
16    /// Returns the name of user.
17    pub fn username(&self) -> &str {
18        self.as_ref().username()
19    }
20}
21
22impl fmt::Debug for User {
23    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24        f.debug_struct("User")
25            .field("username", &self.username())
26            .finish()
27    }
28}
29
30/// Returns stream which yields [User]s.
31///
32/// ## Compatibility
33///
34/// For `musl` target environment this stream always will be empty,
35/// see [#141](https://github.com/heim-rs/heim/issues/141).
36///
37/// [User]: ./struct.User.html
38pub fn users() -> impl Stream<Item = Result<User>> {
39    sys::users().map_ok(Into::into)
40}