pub struct PathBuf(/* private fields */);Expand description
Owned path type.
Paths are mostly arbitrary sequences of bytes, with two restrictions:
- The path cannot contain any null bytes.
- Each component of the path must be no longer than 255 bytes.
Implementations§
Source§impl PathBuf
impl PathBuf
Sourcepub fn new<P>(p: &P) -> Self
pub fn new<P>(p: &P) -> Self
Create a new PathBuf.
This panics if the input is invalid, use Path::try_from if
error handling is desired.
§Panics
Panics if the path contains any null bytes or if a component of the path is longer than 255 bytes.
Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
Get whether the path is absolute (starts with /).
Sourcepub fn display(&self) -> BytesDisplay<'_>
pub fn display(&self) -> BytesDisplay<'_>
Get an object that implements Display to allow conveniently
printing paths that may or may not be valid UTF-8. Non-UTF-8
characters will be replaced with ‘�’.
Sourcepub fn push(&mut self, path: impl AsRef<[u8]>)
pub fn push(&mut self, path: impl AsRef<[u8]>)
Append to the path.
This will add a separator if needed. Note that if the argument
is an absolute path, self will be replaced with that path.
§Panics
Panics if the argument is not a valid path, or if memory cannot be allocated for the resulting path.
Sourcepub fn join(&self, path: impl AsRef<[u8]>) -> Self
pub fn join(&self, path: impl AsRef<[u8]>) -> Self
Create a new PathBuf joining self with path.
This will add a separator if needed. Note that if the argument
is an absolute path, the returned value will be equal to path.
§Panics
Panics if the argument is not a valid path.
Sourcepub fn components(&self) -> Components<'_> ⓘ
pub fn components(&self) -> Components<'_> ⓘ
Get an iterator over each Component in the path.