Struct User

Source
pub struct User { /* private fields */ }
Expand description

Information about a particular user.

For more information, see the module documentation.

Implementations§

Source§

impl User

Source

pub fn new<S: AsRef<OsStr> + ?Sized>( uid: uid_t, name: &S, primary_group: gid_t, ) -> Self

Create a new User with the given user ID, name, and primary group ID, with the rest of the fields filled with dummy values.

This method does not actually create a new user on the system — it should only be used for comparing users in tests.

§Examples
use users::User;

let user = User::new(501, "stevedore", 100);
Source

pub fn uid(&self) -> uid_t

Returns this user’s ID.

§Examples
use users::User;

let user = User::new(501, "stevedore", 100);
assert_eq!(user.uid(), 501);
Source

pub fn name(&self) -> &OsStr

Returns this user’s name.

§Examples
use std::ffi::OsStr;
use users::User;

let user = User::new(501, "stevedore", 100);
assert_eq!(user.name(), OsStr::new("stevedore"));
Source

pub fn primary_group_id(&self) -> gid_t

Returns the ID of this user’s primary group.

§Examples
use users::User;

let user = User::new(501, "stevedore", 100);
assert_eq!(user.primary_group_id(), 100);
Source

pub fn groups(&self) -> Option<Vec<Group>>

Returns a list of groups this user is a member of. This involves loading the groups list, as it is not contained within this type.

§libc functions used
§Examples
use users::User;

let user = User::new(501, "stevedore", 100);
for group in user.groups().expect("User not found") {
    println!("User is in group: {:?}", group.name());
}

Trait Implementations§

Source§

impl Clone for User

Source§

fn clone(&self) -> User

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for User

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl UserExt for User

Source§

fn home_dir(&self) -> &Path

Returns a path to this user’s home directory.
Source§

fn with_home_dir<S: AsRef<OsStr> + ?Sized>(self, home_dir: &S) -> Self

Sets this user value’s home directory to the given string. Can be used to construct test users, which by default come with a dummy home directory string.
Source§

fn shell(&self) -> &Path

Returns a path to this user’s shell.
Source§

fn with_shell<S: AsRef<OsStr> + ?Sized>(self, shell: &S) -> Self

Sets this user’s shell path to the given string. Can be used to construct test users, which by default come with a dummy shell field.
Source§

fn password(&self) -> &OsStr

Returns the user’s encrypted password.
Source§

fn with_password<S: AsRef<OsStr> + ?Sized>(self, password: &S) -> Self

Sets this user’s password to the given string. Can be used to construct tests users, which by default come with a dummy password field.

Auto Trait Implementations§

§

impl Freeze for User

§

impl RefUnwindSafe for User

§

impl Send for User

§

impl Sync for User

§

impl Unpin for User

§

impl UnwindSafe for User

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.