Expand description
Cross-platform path manipulation.
This module provides two types, PathBuf
and Path
(akin to String
and str
), for working with paths abstractly.
Paths can be parsed into Component
s by iterating over the structure
returned by the components
method on Path
. Component
s roughly
correspond to the substrings between path separators (/
or \
). You can
reconstruct an equivalent path from components with the push
method on
PathBuf
; note that the paths may differ syntactically by the
normalization described in the documentation for the components
method.
§Case sensitivity
Unless otherwise indicated path methods that do not access the filesystem,
such as Path::starts_with
and Path::ends_with
, are case sensitive no
matter the platform or filesystem. An exception to this is made for Windows
drive letters.
§Simple usage
Path manipulation includes both parsing components from slices and building new owned paths.
To parse a path, you can create a Path
slice from a str
slice and start asking questions:
use quirks_path::Path;
let path = Path::new("/tmp/foo/bar.txt");
let parent = path.parent();
assert_eq!(parent, Some(Path::new("/tmp/foo")));
let file_stem = path.file_stem();
assert_eq!(file_stem, Some("bar"));
let extension = path.extension();
assert_eq!(extension, Some("txt"));
To build or modify paths, use PathBuf
:
use quirks_path::PathBuf;
// This way works...
let mut path = PathBuf::from("c:\\");
path.push("windows");
path.push("system32");
path.set_extension("dll");
// ... but push is best used if you don't know everything up
// front. If you do, this way is better:
let path: PathBuf = ["c:\\", "windows", "system32.dll"].iter().collect();
Modules§
Structs§
- Ancestors
- An iterator over
Path
and its ancestors. - Components
- An iterator over the
Component
s of aPath
. - Display
- Helper struct for safely printing paths with
format!
and{}
. - Iter
- An iterator over the
Component
s of aPath
, asstr
slices. - Path
- A slice of a path (akin to
str
). - PathBuf
- An owned, mutable path (akin to
String
). - Prefix
Component - A structure wrapping a Windows path prefix as well as its unparsed string representation.
- Strip
Prefix Error - An error returned from
Path::strip_prefix
if the prefix was not found.
Enums§
- Component
- A single component of a path.
- Path
ToUrl Error - Prefix
- Windows path prefixes, e.g.,
C:
or\\server\share
.
Functions§
- absolute
- Makes the path absolute without accessing the filesystem.
- is_
sep_ byte - is_
separator - Determines whether the character is one of the permitted path separators for the current platform.
- is_
verbatim_ sep