whoami/lib.rs
1//! Rust library for getting information about the current user and environment.
2//!
3//! ## Getting Started
4//!
5//! Using the whoami crate is super easy! All of the public items are simple
6//! functions with no parameters that return [`String`]s or [`OsString`]s (with
7//! the exception of [`desktop_env()`], [`platform()`], and [`cpu_arch()`],
8//! which return enums, and [`lang_prefs()`] that returns
9//! [`LanguagePreferences`]). The following example shows how to use all of the
10//! functions (except those that return [`OsString`]):
11//!
12//! ```rust
13//! println!(
14//! "User's Language whoami::lang_prefs(): {}",
15//! whoami::lang_prefs().unwrap_or_default(),
16//! );
17//! println!(
18//! "User's Name whoami::realname(): {}",
19//! whoami::realname().unwrap_or_else(|_| "<unknown>".to_string()),
20//! );
21//! println!(
22//! "User's Username whoami::username(): {}",
23//! whoami::username().unwrap_or_else(|_| "<unknown>".to_string()),
24//! );
25//! println!(
26//! "User's Username whoami::account(): {}",
27//! whoami::account().unwrap_or_else(|_| "<unknown>".to_string()),
28//! );
29//! println!(
30//! "Device's Pretty Name whoami::devicename(): {}",
31//! whoami::devicename().unwrap_or_else(|_| "<unknown>".to_string()),
32//! );
33//! println!(
34//! "Device's Hostname whoami::hostname(): {}",
35//! whoami::hostname().unwrap_or_else(|_| "<unknown>".to_string()),
36//! );
37//! println!(
38//! "Device's Platform whoami::platform(): {}",
39//! whoami::platform(),
40//! );
41//! println!(
42//! "Device's OS Distro whoami::distro(): {}",
43//! whoami::distro().unwrap_or_else(|_| "<unknown>".to_string()),
44//! );
45//! println!(
46//! "Device's Desktop Env. whoami::desktop_env(): {}",
47//! whoami::desktop_env()
48//! .map(|e| e.to_string())
49//! .unwrap_or_else(|| "<unknown>".to_string()),
50//! );
51//! println!(
52//! "Device's CPU Arch whoami::cpu_arch(): {}",
53//! whoami::cpu_arch(),
54//! );
55//! ```
56//!
57//! [`OsString`]: std::ffi::OsString
58//! [`String`]: std::string::String
59
60#![no_std]
61#![warn(
62 anonymous_parameters,
63 missing_copy_implementations,
64 missing_debug_implementations,
65 missing_docs,
66 nonstandard_style,
67 rust_2018_idioms,
68 single_use_lifetimes,
69 trivial_casts,
70 trivial_numeric_casts,
71 unreachable_pub,
72 unused_extern_crates,
73 unused_qualifications,
74 variant_size_differences,
75 unsafe_code
76)]
77#![deny(
78 rustdoc::broken_intra_doc_links,
79 rustdoc::private_intra_doc_links,
80 rustdoc::missing_crate_level_docs,
81 rustdoc::private_doc_tests,
82 rustdoc::invalid_codeblock_attributes,
83 rustdoc::invalid_html_tags,
84 rustdoc::invalid_rust_codeblocks,
85 rustdoc::bare_urls,
86 rustdoc::unescaped_backticks,
87 rustdoc::redundant_explicit_links
88)]
89#![doc(
90 html_logo_url = "https://raw.githubusercontent.com/ardaku/whoami/v2/res/icon.svg",
91 html_favicon_url = "https://raw.githubusercontent.com/ardaku/whoami/v2/res/icon.svg"
92)]
93
94extern crate alloc;
95#[cfg(feature = "std")]
96extern crate std;
97
98mod api;
99mod arch;
100mod conversions;
101mod desktop_env;
102mod error;
103mod langs;
104mod os;
105mod platform;
106mod result;
107
108use self::conversions::OsString;
109pub use self::{
110 api::{
111 account, account_os, cpu_arch, desktop_env, devicename, devicename_os,
112 distro, hostname, lang_prefs, platform, realname, realname_os,
113 username, username_os,
114 },
115 arch::{CpuArchitecture, Width},
116 desktop_env::DesktopEnvironment,
117 error::Error,
118 langs::{Language, LanguagePreferences},
119 platform::Platform,
120 result::Result,
121};