Struct nix::unistd::User

source ·
pub struct User {
    pub name: String,
    pub passwd: CString,
    pub uid: Uid,
    pub gid: Gid,
    pub gecos: CString,
    pub dir: PathBuf,
    pub shell: PathBuf,
    pub class: CString,
    pub change: time_t,
    pub expire: time_t,
}
Available on crate feature user only.
Expand description

Representation of a User, based on libc::passwd

The reason some fields in this struct are String and others are CString is because some fields are based on the user’s locale, which could be non-UTF8, while other fields are guaranteed to conform to NAME_REGEX, which only contains ASCII.

Fields§

§name: String

Username

§passwd: CString

User password (probably hashed)

§uid: Uid

User ID

§gid: Gid

Group ID

§gecos: CString

User information

§dir: PathBuf

Home directory

§shell: PathBuf

Path to shell

§class: CString

Login class

§change: time_t

Last password change

§expire: time_t

Expiration time of account

Implementations§

Get a user by UID.

Internally, this function calls getpwuid_r(3)

Examples
use nix::unistd::{Uid, User};
// Returns an Result<Option<User>>, thus the double unwrap.
let res = User::from_uid(Uid::from_raw(0)).unwrap().unwrap();
assert_eq!(res.name, "root");

Get a user by name.

Internally, this function calls getpwnam_r(3)

Examples
use nix::unistd::User;
// Returns an Result<Option<User>>, thus the double unwrap.
let res = User::from_name("root").unwrap().unwrap();
assert_eq!(res.name, "root");

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.