Skip to main content

expand_tilde

Function expand_tilde 

Source
pub fn expand_tilde(path: impl AsRef<Path>) -> PathBuf
Expand description

Expand a leading ~ or ~/… to the user’s home directory.

Only the leading component is expanded. ~user is left alone — resolving it needs a passwd lookup, and nobody points a per-user store at another user’s home. Anything else, absolute or relative, is returned unchanged.

With no home directory to expand against, the path is returned unchanged: a literal ~ is bad, but inventing a different root would be worse.