Skip to main content

home_dir

Function home_dir 

Source
pub fn home_dir() -> Option<PathBuf>
Expand description

User home directory, or None if it can’t be determined.

  • macOS / Linux: $HOME, falling back to getpwuid_r
  • Windows: %USERPROFILE% (via dirs)

This function accounts for sudo scenarios where $HOME might be /root but we want the actual user’s home directory.

Prefer this over std::env::var("HOME") — the latter returns None on stock Windows and sends us down a fallback path that then hits /tmp (also nonexistent on Windows).