pub struct Path<'a>(/* private fields */);
Expand description
Reference 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<'a> Path<'a>
impl<'a> Path<'a>
Sourcepub fn new<P>(p: &'a P) -> Self
pub fn new<P>(p: &'a P) -> Self
Create a new Path
.
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<'a>
pub fn display(self) -> BytesDisplay<'a>
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 join(self, path: impl AsRef<[u8]>) -> PathBuf
pub fn join(self, path: impl AsRef<[u8]>) -> PathBuf
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<'a> ⓘ
pub fn components(self) -> Components<'a> ⓘ
Get an iterator over each Component
in the path.