Expand description
Expanding tildes in paths.
If the path starts with the ~
character, it will be expanded to the home directory.
Any presence of ~
in paths except for the first character will not be expanded.
The home directory is provided by the home_dir
function.
§Example
There are two main ways to expand tildes with this crate;
the first is to use the expand_tilde
with references:
use expand_tilde::expand_tilde;
let path = "~/.config";
let expanded = expand_tilde(path).unwrap();
println!("{}", expanded.display()); // something like `/home/nekit/.config`
And the other way is to use the sealed extension trait:
use expand_tilde::ExpandTilde;
let path = "~/.config";
let expanded = path.expand_tilde().unwrap();
println!("{}", expanded.display()); // something like `/home/nekit/.config`
The latter method simply calls the former one under the hood.
Enums§
- Error
- Represents errors that can occur during
~
expansion.
Constants§
- TILDE
- The
~
literal.
Traits§
- Expand
Tilde - Represents values that can be tilde-expanded (sealed extension trait).
Functions§
- expand_
tilde - Expands the tilde (
~
) component of the given path to the home directory. - expand_
tilde_ owned - Similar to
expand_tilde
, but accepts the path by value and returns owned paths. - home_
dir - Wraps
home::home_dir
to improve diagnostics.
Type Aliases§
- Result
- The result type used by this crate.