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 |
#694 in Filesystem
239 downloads per month
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
~170–670KB
~15K SLoC