Skip to main content

expand_path

Function expand_path 

Source
pub fn expand_path(path: &str) -> String
Expand description

Expand ~/ and $HOME / ${HOME} in a path string.

Handles three forms:

  • Leading ~/ → replaced with the home directory
  • ~ alone → replaced with the home directory
  • $HOME or ${HOME} anywhere in the string → replaced with the home dir

The home directory is resolved from HOME, falling back to USERPROFILE on Windows. Other environment variables and absolute paths are returned unchanged. Returns the input unchanged if no home variable is set.