pub struct Passwd {
pub name: String,
pub passwd: Option<String>,
pub uid: u32,
pub gid: u32,
pub gecos: Option<String>,
pub dir: String,
pub shell: String,
}Expand description
The main struct for the library, a safe version
of the POSIX struct passwd
There are 2 ways to construct a Passwd instance (other
than assigning fields by hand). You can look up a user account
by username with Passwd::from_name(String), or by uid with
Passwd::from_uid(u32).
There is a shortcut function, Passwd::current_user(), which is just
short for Passwd::from_uid(unsafe { libc::getuid() } as u32).
Fields§
§name: String§passwd: Option<String>§uid: u32§gid: u32§gecos: Option<String>§dir: String§shell: StringImplementations§
Source§impl Passwd
impl Passwd
Sourcepub fn from_name(name: &str) -> Result<Option<Passwd>, PwdError>
pub fn from_name(name: &str) -> Result<Option<Passwd>, PwdError>
Looks up the username and returns a Passwd with the user’s values, if the user is found
This is Result<Option<>> because the operation to convert a rust String to a cstring could fail
§Example
use pwd::Passwd;
let pwd = Passwd::from_name("bob")?;
if let Some(passwd) = pwd {
println!("uid is {}", passwd.uid);
}Sourcepub fn from_uid(uid: u32) -> Option<Passwd>
pub fn from_uid(uid: u32) -> Option<Passwd>
Looks up the uid and returns a Passwd with the user’s values, if the user is found
§Example
use libc::getuid;
use pwd::Passwd;
let uid = unsafe { getuid() };
let pwd = Passwd::from_uid(uid as u32);
if let Some(passwd) = pwd {
println!("username is {}", passwd.name);
}Sourcepub fn current_user() -> Option<Passwd>
pub fn current_user() -> Option<Passwd>
Shortcut for Passwd::from_uid(libc::getuid() as u32), so see the docs for that constructor
§Example
use pwd::Passwd;
let pwd = Passwd::current_user();
if let Some(passwd) = pwd {
println!("username is {}", passwd.name);
}Trait Implementations§
impl StructuralPartialEq for Passwd
Auto Trait Implementations§
impl Freeze for Passwd
impl RefUnwindSafe for Passwd
impl Send for Passwd
impl Sync for Passwd
impl Unpin for Passwd
impl UnsafeUnpin for Passwd
impl UnwindSafe for Passwd
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<A> DynCastExt for A
impl<A> DynCastExt for A
Source§fn dyn_cast<T>(
self,
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source>where
A: DynCastExtHelper<T>,
T: ?Sized,
fn dyn_cast<T>(
self,
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source>where
A: DynCastExtHelper<T>,
T: ?Sized,
Source§fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target
fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target
Source§fn dyn_cast_adv<F, T>(
self,
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source>
fn dyn_cast_adv<F, T>( self, ) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source>
Source§fn dyn_cast_with_config<C>(
self,
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source>where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
fn dyn_cast_with_config<C>(
self,
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source>where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more