Struct abscissa_core::path::AbsPath
source · pub struct AbsPath(_);
Expand description
A reference type for a canonical filesystem path
More specifically: it is at least guaranteed to be canonical at the time it is created. There are potential TOCTTOU problems if the underlying filesystem structure changes after path canonicalization.
Implementations§
source§impl CanonicalPath
impl CanonicalPath
sourcepub fn new<P>(path: &P) -> Result<&CanonicalPath, Error>where
P: AsRef<Path> + ?Sized,
pub fn new<P>(path: &P) -> Result<&CanonicalPath, Error>where
P: AsRef<Path> + ?Sized,
Create a canonical path, returning error if the supplied path is not canonical
sourcepub unsafe fn from_path_unchecked<P>(path: &P) -> &CanonicalPathwhere
P: AsRef<Path> + ?Sized,
pub unsafe fn from_path_unchecked<P>(path: &P) -> &CanonicalPathwhere
P: AsRef<Path> + ?Sized,
Create a canonical path from a path, skipping the canonicalization check
This uses the same unsafe reference conversion tricks as std
to
convert from AsRef<Path>
to AsRef<CanonicalPath>
, i.e. &CanonicalPath
is a newtype for &Path
in the same way &Path
is a newtype for &OsStr
.
sourcepub fn to_canonical_path_buf(&self) -> CanonicalPathBuf
pub fn to_canonical_path_buf(&self) -> CanonicalPathBuf
Convert a canonical path reference into an owned CanonicalPathBuf
sourcepub fn parent(&self) -> Result<CanonicalPathBuf, Error>
pub fn parent(&self) -> Result<CanonicalPathBuf, Error>
Return a canonical parent path of this path, or io::Error
if the
path is the root directory or another canonicalization error occurs.
sourcepub fn file_name(&self) -> Option<&OsStr>
pub fn file_name(&self) -> Option<&OsStr>
Returns the final component of the path, if there is one.
sourcepub fn starts_with<P>(&self, base: P) -> boolwhere
P: AsRef<Path>,
pub fn starts_with<P>(&self, base: P) -> boolwhere
P: AsRef<Path>,
Determines whether base is a prefix of self.
sourcepub fn ends_with<P>(&self, child: P) -> boolwhere
P: AsRef<Path>,
pub fn ends_with<P>(&self, child: P) -> boolwhere
P: AsRef<Path>,
Determines whether child is a suffix of self.
sourcepub fn file_stem(&self) -> Option<&OsStr>
pub fn file_stem(&self) -> Option<&OsStr>
Extracts the stem (non-extension) portion of self.file_name
.
sourcepub fn extension(&self) -> Option<&OsStr>
pub fn extension(&self) -> Option<&OsStr>
Extracts the extension of self.file_name
, if possible.
sourcepub fn with_file_name<S>(&self, file_name: S) -> Result<CanonicalPathBuf, Error>where
S: AsRef<OsStr>,
pub fn with_file_name<S>(&self, file_name: S) -> Result<CanonicalPathBuf, Error>where
S: AsRef<OsStr>,
Creates an owned CanonicalPathBuf
like self but with the given file name.
sourcepub fn with_extension<S>(&self, extension: S) -> Result<CanonicalPathBuf, Error>where
S: AsRef<OsStr>,
pub fn with_extension<S>(&self, extension: S) -> Result<CanonicalPathBuf, Error>where
S: AsRef<OsStr>,
Creates an owned CanonicalPathBuf
like self but with the given extension.
sourcepub fn components(&self) -> Components<'_>
pub fn components(&self) -> Components<'_>
Produces an iterator over the Component
s of a path
sourcepub fn iter(&self) -> Iter<'_>
pub fn iter(&self) -> Iter<'_>
Produces an iterator over the path’s components viewed as
OsStr
slices.
sourcepub fn display(&self) -> Display<'_>
pub fn display(&self) -> Display<'_>
Returns an object that implements Display
for safely printing
paths that may contain non-Unicode data.
sourcepub fn metadata(&self) -> Result<Metadata, Error>
pub fn metadata(&self) -> Result<Metadata, Error>
Queries the file system to get information about a file, directory, etc.
Unlike the std
version of this method, it will not follow symlinks,
since as a canonical path we should be symlink-free.
sourcepub fn join<P>(&self, path: P) -> Result<CanonicalPathBuf, Error>where
P: AsRef<Path>,
pub fn join<P>(&self, path: P) -> Result<CanonicalPathBuf, Error>where
P: AsRef<Path>,
Join a path onto a canonical path, returning a CanonicalPathBuf
.
Trait Implementations§
source§impl AsRef<CanonicalPath> for CanonicalPathBuf
impl AsRef<CanonicalPath> for CanonicalPathBuf
source§fn as_ref(&self) -> &CanonicalPath
fn as_ref(&self) -> &CanonicalPath
source§impl AsRef<Path> for CanonicalPath
impl AsRef<Path> for CanonicalPath
source§impl Borrow<CanonicalPath> for CanonicalPathBuf
impl Borrow<CanonicalPath> for CanonicalPathBuf
source§fn borrow(&self) -> &CanonicalPath
fn borrow(&self) -> &CanonicalPath
source§impl Debug for CanonicalPath
impl Debug for CanonicalPath
source§impl Hash for CanonicalPath
impl Hash for CanonicalPath
source§impl Ord for CanonicalPath
impl Ord for CanonicalPath
source§impl PartialEq<CanonicalPath> for CanonicalPath
impl PartialEq<CanonicalPath> for CanonicalPath
source§fn eq(&self, other: &CanonicalPath) -> bool
fn eq(&self, other: &CanonicalPath) -> bool
source§impl PartialOrd<CanonicalPath> for CanonicalPath
impl PartialOrd<CanonicalPath> for CanonicalPath
source§fn partial_cmp(&self, other: &CanonicalPath) -> Option<Ordering>
fn partial_cmp(&self, other: &CanonicalPath) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more