Function expand_path

Source
pub fn expand_path(path: impl AsRef<str>) -> PathBuf
Expand description

Expand the user’s home directory and any environment variables references in the given path.

This function is designed to emulate the behavior of Mercurial’s util.expandpath function, which in turn uses Python’s os.path.expand{user,vars} functions. This results in behavior that is notably different from the default expansion behavior of the shellexpand crate. In particular:

  • If a reference to an environment variable is missing or invalid, the reference is left unchanged in the resulting path rather than emitting an error.

  • Home directory expansion explicitly happens after environment variable expansion, meaning that if an environment variable is expanded into a string starting with a tilde (~), the tilde will be expanded into the user’s home directory.