Skip to main content

resolve_path

Function resolve_path 

Source
pub fn resolve_path(path: &str) -> PathResult<PathBuf>
Expand description

Resolves a path string that may contain environment variables

This method expands environment variables in the format $VAR or ${VAR}, resolves tilde (~) to the user’s home directory when it appears at the start of the path, and converts relative paths to absolute paths based on the current working directory.

§Arguments

  • path - The path string that may contain environment variables and tilde expansion

§Returns

Returns an absolute PathBuf with all variables expanded, or a PathError if the path is invalid or variables cannot be resolved.

§Errors

§Example

use soar_utils::error::PathResult;
use soar_utils::path::resolve_path;

fn main() -> PathResult<()> {
    let resolved = resolve_path("$HOME/path/to/file")?;
    println!("Resolved path is {:#?}", resolved);
    Ok(())
}