[][src]Crate etc_passwd

Get user information stored in the password file /etc/passwd.

This crate provides a safe wrapper for libc functions such as getpwnam_r(3) and getpwuid_r(3).


Add this to your Cargo.toml:

etc-passwd = "0.1.1"


Get a current user information:

use etc_passwd::Passwd;

if let Some(passwd) = Passwd::current_user()? {
    println!("current user name is: {}", passwd.name.to_str()?);
    println!("your user id is: {}", passwd.uid);
    println!("your group id is: {}", passwd.gid);
    println!("your full name is: {}", passwd.gecos.to_str()?);
    println!("your home directory is: {}", passwd.dir.to_str()?);
    println!("your login shell is: {}", passwd.shell.to_str()?);
} else {
    println!("oops! current user is not found... who are you?");



Representation of a user information stored in the password file /etc/passwd.