4 releases (1 stable)

1.0.0 Oct 22, 2023
0.1.2 Aug 5, 2023
0.1.1 Aug 5, 2023
0.1.0 Aug 5, 2023

#5 in #textual

Download history 19/week @ 2024-03-11 5/week @ 2024-03-18 39/week @ 2024-04-01 85/week @ 2024-04-08 51/week @ 2024-04-15 79/week @ 2024-04-22 95/week @ 2024-04-29 58/week @ 2024-05-06 19/week @ 2024-05-13 24/week @ 2024-05-20 13/week @ 2024-05-27 18/week @ 2024-06-03 20/week @ 2024-06-10 14/week @ 2024-06-17 20/week @ 2024-06-24

73 downloads per month
Used in 7 crates

ISC license

24KB
353 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 file_paths::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 (\\). 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 file_paths::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.4–4MB
~71K SLoC