Crate expand_tilde

Source
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§

ExpandTilde
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.