Skip to main content

expand_path

Function expand_path 

Source
pub fn expand_path(path: &str) -> Result<PathBuf, ConfigError>
Expand description

Expands ~ in paths to the home directory.

If the path starts with ~, it is replaced with the user’s home directory. Otherwise, the path is returned unchanged (converted to PathBuf).

§Errors

Returns ConfigError::NoHomeDirectory if the path starts with ~ and the home directory cannot be determined.

§Examples

use txgate_core::config_loader::expand_path;

// Expands ~ to home directory
let path = expand_path("~/.txgate/config.toml").expect("failed to expand path");
// path is something like "/home/user/.txgate/config.toml"

// Absolute paths are unchanged
let path = expand_path("/etc/txgate/config.toml").expect("failed to expand path");
assert_eq!(path.to_string_lossy(), "/etc/txgate/config.toml");