Skip to main content

PathExt

Trait PathExt 

Source
pub trait PathExt {
    // Required methods
    fn normalize(&self) -> PathBuf;
    fn canonicalize_or_self(&self) -> PathBuf;
    fn file_name_str(&self) -> String;
}
Expand description

Extension trait that adds path normalization and safety methods to Path.

Delegates to the existing free functions in this module, providing a more ergonomic call-site syntax:

use vtcode_commons::paths::PathExt;
use std::path::Path;

let normalized = Path::new("/tmp/project/src/../src/lib.rs").normalize();

Required Methods§

Source

fn normalize(&self) -> PathBuf

Normalize a path by resolving . and .. components lexically.

Source

fn canonicalize_or_self(&self) -> PathBuf

Canonicalize with fallback to the original path if canonicalization fails.

Source

fn file_name_str(&self) -> String

Extract the filename from a path as a String, with fallback to the full path when no filename component exists.

Unlike Path::file_name which returns Option<&OsStr>, this method always returns a String and falls back gracefully.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PathExt for Path

Implementors§