Thanks to visit codestin.com
Credit goes to docs.rs

Crate whoami

Crate whoami 

Source
Expand description

Rust library for getting information about the current user and environment.

§Getting Started

Using the whoami crate is super easy! All of the public items are simple functions with no parameters that return Strings or OsStrings (with the exception of desktop_env(), platform(), and cpu_arch(), which return enums, and lang_prefs() that returns LanguagePreferences). The following example shows how to use all of the functions (except those that return OsString):

println!(
    "User's Language        whoami::lang_prefs():          {}",
    whoami::lang_prefs().unwrap_or_default(),
);
println!(
    "User's Name            whoami::realname():            {}",
    whoami::realname().unwrap_or_else(|_| "<unknown>".to_string()),
);
println!(
    "User's Username        whoami::username():            {}",
    whoami::username().unwrap_or_else(|_| "<unknown>".to_string()),
);
println!(
    "User's Username        whoami::account():             {}",
    whoami::account().unwrap_or_else(|_| "<unknown>".to_string()),
);
println!(
    "Device's Pretty Name   whoami::devicename():          {}",
    whoami::devicename().unwrap_or_else(|_| "<unknown>".to_string()),
);
println!(
    "Device's Hostname      whoami::hostname():            {}",
    whoami::hostname().unwrap_or_else(|_| "<unknown>".to_string()),
);
println!(
    "Device's Platform      whoami::platform():            {}",
    whoami::platform(),
);
println!(
    "Device's OS Distro     whoami::distro():              {}",
    whoami::distro().unwrap_or_else(|_| "<unknown>".to_string()),
);
println!(
    "Device's Desktop Env.  whoami::desktop_env():         {}",
    whoami::desktop_env()
        .map(|e| e.to_string())
        .unwrap_or_else(|| "<unknown>".to_string()),
);
println!(
    "Device's CPU Arch      whoami::cpu_arch():            {}",
    whoami::cpu_arch(),
);

Structs§

Error
An I/O error; can be converted to std::io::Error.
Language
A spoken language identifier
LanguagePreferences
Language preferences for a user

Enums§

CpuArchitecture
The architecture of a CPU
DesktopEnvironment
The desktop environment of a system
Platform
The underlying platform for a system
Width
The address width of a CPU architecture

Functions§

account
Get the user’s account name; usually just the username, but may include an account server hostname.
account_os
Get the user’s account name; usually just the username, but may include an account server hostname.
cpu_arch
Get the CPU Architecture.
desktop_env
Get the desktop environment (if any).
devicename
Get the device name (also known as “Pretty Name”).
devicename_os
Get the device name (also known as “Pretty Name”).
distro
Get the name of the operating system distribution and (possibly) version.
hostname
Get the host device’s hostname.
lang_prefs
Get the user’s preferred language(s).
platform
Get the platform.
realname
Get the user’s real (full) name.
realname_os
Get the user’s real (full) name.
username
Get the user’s username.
username_os
Get the user’s username.

Type Aliases§

Result
This crate’s convenience type alias for Results