Skip to main content

normalize_path

Function normalize_path 

Source
pub fn normalize_path(path: &Path) -> Option<String>
Expand description

Normalize a path by removing . and .. components

This function:

  • Removes . components (current directory)
  • Resolves .. components (parent directory)
  • Converts path to forward slashes for consistency
  • Preserves relative vs absolute nature of the path

§Arguments

  • path - The path to normalize

§Returns

A normalized path string, or None if the path cannot be normalized (e.g., too many .. components going above root)

§Examples

use sqry_core::graph::path_resolver::normalize_path;
use std::path::Path;

assert_eq!(
    normalize_path(Path::new("src/./app/../lib/utils")).unwrap(),
    "src/lib/utils"
);

assert_eq!(
    normalize_path(Path::new("./foo/./bar")).unwrap(),
    "foo/bar"
);