std::path
本頁內容
API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。
Path, a UTF-8 path value with
Python-style / joining. Separators follow the target: / on Unix;
\ or / on Windows, where a path may start with a prefix (C:,
\\server\share, \\?\.., \\.\..), is absolute only with a prefix
and a root, and join writes \.
Path is immutable: / returns a new one, p /= q is p = p / q.
RawPath holds the OS form (Unix bytes, Windows UTF-16); the fs layer
never produces one - it reports non-UTF-8 names as InvalidData.
Structs
PathSource
pub struct PathA filesystem path, held as text. Not checked against the filesystem until an fs call uses it.
The path
sspells.The empty path.
Sourcepub const fn from_components<I: IntoIterator<Item = str>>(§components: I) -> Path The path joining each of
componentsin turn (Path::join).The path as text.
The path as OS bytes (Unix) or WTF-16 units (Windows).
Unix: rooted. Windows: a prefix and a root (
C:\x,\\srv\s\x).truewhen the path is not absolute.truewhen the path starts at a root (/,\,C:\).The path without its last component;
nonefor/and"".Path::new("a").parent()is""(as in Rust).The last component unless it is
..//.file_namewithout its extension.After the last
.offile_name(nonefor.bashrc,a).
Sourcepub const fn components(§self) -> Components The components, front to back: repeated separators and inner
.dropped, a leading.and every..kept.self, its parent, its grandparent, ...other(aPathor astr) appended; an absoluteotherreplacesself. Windows: so does one with a prefix (D:x), and a rooted one without (\x) keepsself's prefix.selfwith its last component replaced byname.selfwith its extension replaced byext; an emptyextremoves it.Component-wise prefix test.
Component-wise suffix test.
The rest of
selfafterbase(component-wise), ornonewhenselfdoes not start with it (str::strip_prefixalike).Lexical
./..resolution (no filesystem access).Whether the path exists (symlinks followed); any error reads as
false.Whether the path is a regular file (symlinks followed);
falseon any error.Whether the path is a directory (symlinks followed);
falseon any error.Whether the path itself is a symlink;
falseon any error.The path's metadata, symlinks followed (
fs::metadata).Absolute, symlinks resolved (
realpath).
RawPathSource
pub struct RawPathOS path bytes that need not be UTF-8: Unix bytes.
RawPathSource
pub struct RawPathAn OS path that need not be valid UTF-16: Windows WTF-16 units (lone surrogates allowed).
The path with OS bytes
bytes.The OS bytes.
The path; throws if the bytes are not UTF-8.
The path with each maximal ill-formed subsequence replaced by one U+FFFD (
str::from_utf8_lossy; Windows: each lone surrogate).The path of the UTF-16 units
wide, which need not be valid.The UTF-16 units of the path.
The path; throws if the units are not valid UTF-16 (
valid_up_tocounts UTF-16 units here).The path with each lone surrogate replaced by U+FFFD.
Trait implementations 1
impl Debug for RawPath
ComponentsSource
pub struct ComponentsPath::components: the parts, from the root or first name.
AncestorsSource
pub struct AncestorsPath::ancestors: the path, then each parent up to the root.
Enums
ComponentSource
pub enum ComponentOne piece of a path (Path::components).
The component as it is written in a path (
/,.,.., the name).
Trait implementations 1
impl Debug for Component
Traits
AsPathSource
pub trait AsPathWhat the fs functions take: a Path or a str spelling one.
selfas aPath.