pub struct User { /* private fields */ }
Expand description
Information about a particular user.
For more information, see the module documentation.
Implementations
sourceimpl User
impl User
sourcepub fn new<S: AsRef<OsStr> + ?Sized>(
uid: uid_t,
name: &S,
primary_group: gid_t
) -> Self
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);
sourcepub fn uid(&self) -> uid_t
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);
sourcepub fn name(&self) -> &OsStr
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"));
sourcepub fn primary_group_id(&self) -> gid_t
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);
sourcepub fn groups(&self) -> Option<Vec<Group>>
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
sourceimpl UserExt for User
impl UserExt for User
sourcefn with_home_dir<S: AsRef<OsStr> + ?Sized>(self, home_dir: &S) -> Self
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. Read more
Auto Trait Implementations
impl RefUnwindSafe for User
impl Send for User
impl Sync for User
impl Unpin for User
impl UnwindSafe for User
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more