37 releases (20 breaking)

0.21.1 Apr 30, 2026
0.20.0 Apr 24, 2026
0.19.2 Mar 22, 2026
0.18.1 Dec 31, 2025
0.4.1 Jul 22, 2023

#896 in Filesystem

Download history 684787/week @ 2026-01-22 887888/week @ 2026-01-29 1079902/week @ 2026-02-05 1079859/week @ 2026-02-12 654683/week @ 2026-02-19 856569/week @ 2026-02-26 770811/week @ 2026-03-05 765716/week @ 2026-03-12 668037/week @ 2026-03-19 670228/week @ 2026-03-26 769977/week @ 2026-04-02 555861/week @ 2026-04-09 501838/week @ 2026-04-16 585191/week @ 2026-04-23 620523/week @ 2026-04-30 637760/week @ 2026-05-07

2,437,056 downloads per month
Used in 714 crates (14 directly)

MIT/Apache

280KB
5K SLoC

A crate with file-system specific utilities.

Examples

use std::path::{Path, PathBuf};

use gix_fs::{
    stack::{Delegate, ToNormalPathComponents},
    Stack,
};

let components = "src/lib.rs"
    .to_normal_path_components()
    .collect::<Result<Vec<_>, _>>()?;
assert_eq!(
    components
        .into_iter()
        .map(|component| component.to_string_lossy().into_owned())
        .collect::<Vec<_>>(),
    vec!["src", "lib.rs"]
);

#[derive(Default)]
struct Recorder {
    directories: Vec<PathBuf>,
    paths: Vec<PathBuf>,
}

impl Delegate for Recorder {
    fn push_directory(&mut self, stack: &Stack) -> std::io::Result<()> {
        self.directories.push(stack.current_relative().to_path_buf());
        Ok(())
    }

    fn push(&mut self, _is_last_component: bool, stack: &Stack) -> std::io::Result<()> {
        self.paths.push(stack.current_relative().to_path_buf());
        Ok(())
    }

    fn pop_directory(&mut self) {}
}

let capabilities = gix_fs::Capabilities::probe_dir(dir.path());
let mut stack = Stack::new(dir.path().to_path_buf());
let mut recorder = Recorder::default();
stack.make_relative_path_current("src/lib.rs", &mut recorder)?;

assert_eq!(stack.current_relative(), Path::new("src/lib.rs"));
assert_eq!(recorder.directories[0], Path::new(""));
assert_eq!(recorder.paths, vec![PathBuf::from("src"), PathBuf::from("src/lib.rs")]);
assert_eq!(gix_fs::current_dir(capabilities.precompose_unicode)?, std::env::current_dir()?);

Dependencies

~1.5–2.3MB
~55K SLoC