pub fn home_dir() -> Option<PathBuf>Expand description
Returns the path to the user’s home directory.
The returned value depends on the operating system and is either a Some, containing a value from the following table, or a None.
| Platform | Value | Example |
|---|---|---|
| Linux | $HOME | /home/alice |
| macOS | $HOME | /Users/Alice |
| Windows | {FOLDERID_Profile} | C:\Users\Alice |
§Linux and macOS:
- Use
$HOMEif it is set and not empty. - If
$HOMEis not set or empty, then the functiongetpwuid_ris used to determine the home directory of the current user. - If
getpwuid_rlacks an entry for the current user id or the home directory field is empty, then the function returnsNone.
§Windows:
This function retrieves the user profile folder using SHGetKnownFolderPath.
All the examples on this page mentioning $HOME use this behavior.
Note: This function’s behavior differs from std::env::home_dir,
which works incorrectly on Linux, macOS and Windows.