Skip to main content

System Information Retrieval

This code provides functions to retrieve various system information such as disk details, operating system version, hostname, username, and user home directory.

get_disks() -> Vec<String>

Retrieves the mounted points of the system disks.

Returns: A Vec<String> containing the mounted points of the system disks.

get_version() -> String

Retrieves the operating system version.

Returns: A String representing the operating system version.

get_hostname() -> String

Retrieves the hostname of the system.

Returns: A String representing the hostname.

get_username() -> String

Retrieves the username of the current user.

Returns: A String representing the username.

get_user_home() -> PathBuf

Retrieves the home directory path of the current user.

Returns: A PathBuf representing the user's home directory path.

Disk Retrieval

The function get_disks() uses the sysinfo crate to retrieve system disk information. It iterates over the disks and extracts their mounted points into a Vec<String>.

Operating System Version Retrieval

The function get_version() utilizes the os_info crate to retrieve the operating system information. It obtains the operating system type using os_info::get().os_type() and maps it to a human-readable string. The operating system version is retrieved using os_info::get().version(), and the version information is formatted into a string.

Hostname Retrieval

The function get_hostname() leverages the whoami crate to retrieve the hostname of the system using whoami::hostname().

Username Retrieval

The function get_username() uses the whoami crate to retrieve the username of the current user using whoami::username().

User Home Directory Retrieval

The function get_user_home() utilizes the home crate to retrieve the home directory path of the current user. It uses home::home_dir() to obtain the Option<PathBuf> representing the user's home directory. If the home directory is found, it is returned as a PathBuf; otherwise, a fallback value of "unknown" is used.