4 stable releases

new 1.1.1 Feb 22, 2025
1.0.1 Feb 21, 2025
1.0.0 Feb 19, 2025

#7 in #absolute

Download history

94 downloads per month
Used in 2 crates (via mxmlextrema-as3parser)

ISC license

25KB
360 lines

File Paths

Work with textual file paths, including relativity and resolution. Features:

  • Variant: FlexPath methods consider absolute paths according to the path's FlexPathVariant. Two variants are supported: Common and Windows. The native variant can be deduced directly through _native suffixed methods.

Requirements:

  • The Rust standard library (std).

Example

use realhydroper_path::FlexPath;

assert_eq!("a", FlexPath::new_common("a/b").resolve("..").to_string());
assert_eq!("a", FlexPath::new_common("a/b/..").to_string());
assert_eq!("a/b/c/d/e", FlexPath::from_n_common(["a/b", "c/d", "e/f", ".."]).to_string());
assert_eq!("../../c/d", FlexPath::new_common("/a/b").relative("/c/d"))

lib.rs:

Work with file paths by text only.

In the Windows operating system, absolute paths may either start with a drive letter followed by a colon, or an UNC path prefix (\\), or an extended drive letter prefix (\\?\X:). Therefore, this crate provides a FlexPath that is based on a variant ([FlexPathVariant]), which you don't need to always specify. This variant indicates whether to interpret Windows absolute paths or not.

There are two FlexPathVariant variants currently:

  • Common
  • Windows

The constant FlexPathVariant::native() is one of these variants based on the target platform. For the Windows operating system, it is always Windows. For other platforms, it's always Common.

Example

use realhydroper_path::FlexPath;

assert_eq!("a", FlexPath::new_common("a/b").resolve("..").to_string());
assert_eq!("a", FlexPath::new_common("a/b/..").to_string());
assert_eq!("a/b/c/d/e", FlexPath::from_n_common(["a/b", "c/d", "e/f", ".."]).to_string());
assert_eq!("../../c/d", FlexPath::new_common("/a/b").relative("/c/d"));

Dependencies

~2.3–4MB
~69K SLoC