Search

Lib.rs

› Filesystem
#standard-path #absolute-path

dirge

Convenient extensions to the standard library's path types

Owned by Daniel Levin.

  • Install
  • API reference
  • GitHub repo (daniel-levin)

4 releases

Uses new Rust 2024

0.1.3 Jul 27, 2025
0.1.2 Jun 25, 2025
0.1.1 Jun 24, 2025
0.1.0 Jun 24, 2025

#1048 in Filesystem

Download history

239 downloads per month

Unlicense/MIT

19KB
454 lines

dirge

Examples

Absolute paths are just paths


use dirge::{AbsPath, AbsPathBuf};
use std::path::Path;

let a: AbsPathBuf = example();
let b: &AbsPath = &a;
let c: &Path = &a;
let d: &Path = &b;

/// Precondition enforced by type system
fn needs_abs_path(p: &AbsPath) {
}

/// But they go anywhere the standard library's paths do!
let _ = std::fs::read_to_string(&a);

Relative paths provide similar guarantees

use dirge::{RelPath, RelPathBuf};
use std::path::Path;

let rel = RelPathBuf::new("src/main.rs").unwrap();
let rel_ref: &RelPath = &rel;
let path_ref: &Path = &rel;

/// Type system enforces relative path requirement
fn needs_relative_path(p: &RelPath) {
}

needs_relative_path(&rel);

Normalized paths remove redundant components

use dirge::{NormPath, NormPathBuf};
use std::path::Path;

let norm = NormPathBuf::new("path/./to/../file.txt").unwrap();
assert_eq!(norm.to_string_lossy(), "path/file.txt");

let norm_ref: &NormPath = &norm;
let path_ref: &Path = &norm;

/// Type system guarantees normalized paths
fn needs_normalized_path(p: &NormPath) {
}

needs_normalized_path(&norm);

Background

This crate provides portable extensions to the standard library's path functionality. Our types have specific usages while incurring no storage overhead. For example, [AbsPathBuf] and std::path::PathBuf have identical in-memory representations, but the former is guaranteed to be an absolute path.

This crate has several goals:

  • Enhance correctness through specific types.
  • Be conducive to re-exporting.
  • Be portable.

License: Unlicense/MIT

Dependencies

~120–550KB
~13K SLoC

  • ref-cast
  • optional serde+derive
  • dev serde_test
See also: path-absolutize, ra_ap_paths, dav-server, normpath, path-dedot, tree-fs, fsx, opfs, switchy_fs, rusoto_efs, tempfile

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.