common-path 1.0.0

Finds the common prefix between a set of paths
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented3 out of 3 items with examples
  • Size
  • Source code size: 23.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.11 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pwoolcoc

Calculates the common prefix for a set of paths, if a common prefix exists

Example

# extern crate common_path;
use std::path::{PathBuf, Path};
use common_path::common_path;

# fn main() {
let baz = Path::new("/foo/bar/baz");
let quux = Path::new("/foo/bar/quux");
let prefix = common_path(baz, quux).unwrap();
assert_eq!(prefix, Path::new("/foo/bar").to_path_buf());
# }

Or for more than 2 paths:

# extern crate common_path;
use std::path::{PathBuf, Path};
use common_path::common_path_all;

# fn main() {
let baz = Path::new("/foo/bar/baz");
let quux = Path::new("/foo/bar/quux");
let foo = Path::new("/foo/bar/foo");
let prefix = common_path_all(vec![baz, quux, foo]).unwrap();
assert_eq!(prefix, Path::new("/foo/bar").to_path_buf());
# }