[][src]Struct canonical_path::CanonicalPathBuf

pub struct CanonicalPathBuf(_);

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.

Methods

impl CanonicalPathBuf[src]

pub fn canonicalize<P>(path: P) -> Result<Self> where
    P: AsRef<Path>, 
[src]

Create a canonical path by first canonicalizing the given path.

pub fn new<P>(path: P) -> Result<Self> where
    P: AsRef<Path>, 
[src]

Create a canonical path, returning error if the supplied path is not canonical.

pub fn as_canonical_path(&self) -> &CanonicalPath[src]

Return a CanonicalPath reference.

pub fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S)[src]

Updates self's filename ala the same method on PathBuf

pub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool[src]

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.

pub fn into_path_buf(self) -> PathBuf[src]

Consumes the CanonicalPathBuf, yielding its internal PathBuf storage.

pub fn into_os_string(self) -> OsString[src]

Consumes the CanonicalPathBuf, yielding its internal OsString storage.

pub fn as_path(&self) -> &Path[src]

Return a Path reference.

pub fn as_os_str(&self) -> &OsStr[src]

Return an OsStr reference.

pub fn to_str(&self) -> Option<&str>[src]

Yields a &str slice if the path is valid unicode.

pub fn parent(&self) -> Result<CanonicalPathBuf>[src]

Return a canonical parent path of this path, or io::Error if the path is the root directory or another canonicalization error occurs.

pub fn file_name(&self) -> Option<&OsStr>[src]

Returns the final component of the path, if there is one.

pub fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool[src]

Determines whether base is a prefix of self.

pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool[src]

Determines whether child is a suffix of self.

pub fn file_stem(&self) -> Option<&OsStr>[src]

Extracts the stem (non-extension) portion of self.file_name.

pub fn extension(&self) -> Option<&OsStr>[src]

Extracts the extension of self.file_name, if possible.

pub fn with_file_name<S: AsRef<OsStr>>(
    &self,
    file_name: S
) -> Result<CanonicalPathBuf>
[src]

Creates an owned CanonicalPathBuf like self but with the given file name.

pub fn with_extension<S: AsRef<OsStr>>(
    &self,
    extension: S
) -> Result<CanonicalPathBuf>
[src]

Creates an owned CanonicalPathBuf like self but with the given extension.

pub fn components(&self) -> Components[src]

Produces an iterator over the Components of a path

pub fn iter(&self) -> Iter[src]

Produces an iterator over the path's components viewed as OsStr slices.

pub fn display(&self) -> Display[src]

Returns an object that implements Display for safely printing paths that may contain non-Unicode data.

pub fn metadata(&self) -> Result<Metadata>[src]

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.

pub fn join<P: AsRef<Path>>(&self, path: P) -> Result<CanonicalPathBuf>[src]

Join a path onto a canonical path, returning a CanonicalPathBuf.

pub fn read_dir(&self) -> Result<ReadDir>[src]

Returns an iterator over the entries within a directory.

The iterator will yield instances of io::Result. New errors may be encountered after an iterator is initially constructed.

This is an alias to fs::read_dir.

pub fn exists(&self) -> bool[src]

Does this path exist?

pub fn is_file(&self) -> bool[src]

Is this path a file?

pub fn is_dir(&self) -> bool[src]

Is this path a directory?

Trait Implementations

impl PartialEq<CanonicalPathBuf> for CanonicalPathBuf[src]

impl AsRef<Path> for CanonicalPathBuf[src]

impl AsRef<CanonicalPath> for CanonicalPathBuf[src]

impl AsRef<OsStr> for CanonicalPathBuf[src]

impl Clone for CanonicalPathBuf[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Ord for CanonicalPathBuf[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl Eq for CanonicalPathBuf[src]

impl PartialOrd<CanonicalPathBuf> for CanonicalPathBuf[src]

impl Debug for CanonicalPathBuf[src]

impl Hash for CanonicalPathBuf[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Borrow<CanonicalPath> for CanonicalPathBuf[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]