Crate uni_path[−][src]
Platform-independent path manipulation.
This module provides two types, PathBuf
and Path
(akin to String
and str
), for working with paths abstractly. These types are thin wrappers
around String
and str
respectively, meaning that they work directly
on strings.
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 (/
). 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.
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 uni_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 uni_path::PathBuf; // This way works... let mut path = PathBuf::from("/"); path.push("lib"); path.push("libc"); path.set_extension("so"); // ... but push is best used if you don't know everything up // front. If you do, this way is better: let path: PathBuf = ["/", "lib", "libc.so"].iter().collect();
Structs
Ancestors | An iterator over |
Components | |
Iter | |
Path | A slice of a path (akin to |
PathBuf | An owned, mutable path (akin to |
StripPrefixError | An error returned from |
Enums
Component | A single component of a path. |
Constants
MAIN_SEPARATOR | The primary separator of path components for the current platform. |
Functions
is_separator | Determines whether the character is one of the permitted path separators for the current platform. |