pub struct CanonicalPathBuf(/* private fields */);Expand description
An owned path on the filesystem which is guaranteed to be canonical.
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 CanonicalPathBuf
impl CanonicalPathBuf
Sourcepub fn canonicalize<P>(path: P) -> Result<Self>
pub fn canonicalize<P>(path: P) -> Result<Self>
Create a canonical path by first canonicalizing the given path.
Sourcepub fn new<P>(path: P) -> Result<Self>
pub fn new<P>(path: P) -> Result<Self>
Create a canonical path, returning error if the supplied path is not canonical.
Sourcepub fn as_canonical_path(&self) -> &CanonicalPath
pub fn as_canonical_path(&self) -> &CanonicalPath
Return a CanonicalPath reference.
Sourcepub fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S)
pub fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S)
Updates self’s filename ala the same method on PathBuf
Sourcepub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool
pub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool
Updates self.extension to extension.
Returns false and does nothing if self.file_name is None,
returns true and updates the extension otherwise.
If self.extension is None, the extension is added; otherwise it is replaced.
Sourcepub fn into_path_buf(self) -> PathBuf
pub fn into_path_buf(self) -> PathBuf
Consumes the CanonicalPathBuf, yielding its internal PathBuf storage.
Sourcepub fn into_os_string(self) -> OsString
pub fn into_os_string(self) -> OsString
Consumes the CanonicalPathBuf, yielding its internal OsString storage.
Sourcepub fn parent(&self) -> Result<CanonicalPathBuf>
pub fn parent(&self) -> Result<CanonicalPathBuf>
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: AsRef<Path>>(&self, base: P) -> bool
pub fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool
Determines whether base is a prefix of self.
Sourcepub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool
pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool
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: AsRef<OsStr>>(
&self,
file_name: S,
) -> Result<CanonicalPathBuf>
pub fn with_file_name<S: AsRef<OsStr>>( &self, file_name: S, ) -> Result<CanonicalPathBuf>
Creates an owned CanonicalPathBuf like self but with the given file name.
Sourcepub fn with_extension<S: AsRef<OsStr>>(
&self,
extension: S,
) -> Result<CanonicalPathBuf>
pub fn with_extension<S: AsRef<OsStr>>( &self, extension: S, ) -> Result<CanonicalPathBuf>
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 Components 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>
pub fn metadata(&self) -> Result<Metadata>
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: AsRef<Path>>(&self, path: P) -> Result<CanonicalPathBuf>
pub fn join<P: AsRef<Path>>(&self, path: P) -> Result<CanonicalPathBuf>
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<OsStr> for CanonicalPathBuf
impl AsRef<OsStr> for CanonicalPathBuf
Source§impl AsRef<Path> for CanonicalPathBuf
impl AsRef<Path> for CanonicalPathBuf
Source§impl Borrow<CanonicalPath> for CanonicalPathBuf
impl Borrow<CanonicalPath> for CanonicalPathBuf
Source§fn borrow(&self) -> &CanonicalPath
fn borrow(&self) -> &CanonicalPath
Source§impl Clone for CanonicalPathBuf
impl Clone for CanonicalPathBuf
Source§fn clone(&self) -> CanonicalPathBuf
fn clone(&self) -> CanonicalPathBuf
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more