Enum path_abs::PathType

source ·
pub enum PathType {
    File(PathFile),
    Dir(PathDir),
}
Expand description

An an enum containing either a file or a directory.

This is used primarily for:

  • The items returned from PathDir::list
  • Serializing paths of different types.

Note that for symlinks, this returns the underlying file type.

Variants§

Implementations§

source§

impl PathType

source

pub fn new<P: AsRef<Path>>(path: P) -> Result<PathType>

Resolves and returns the PathType of the given path.

If the path exists but is not a file or a directory (i.e. is a symlink), then io::ErrorKind::InvalidInput is returned.

Examples
use path_abs::PathType;

let src = PathType::new("src")?;
source

pub fn try_from<P: Into<PathAbs>>(path: P) -> Result<PathType>

Consume the PathAbs returning the PathType.

source

pub fn unwrap_file(self) -> PathFile

Unwrap the PathType as a PathFile.

Examples
use path_abs::PathType;

let lib = PathType::new("src/lib.rs")?.unwrap_file();
source

pub fn unwrap_dir(self) -> PathDir

Unwrap the PathType as a PathDir.

Examples
use path_abs::PathType;

let src = PathType::new("src")?.unwrap_dir();
source

pub fn is_dir(&self) -> bool

Return whether this variant is PathType::Dir.

source

pub fn is_file(&self) -> bool

Return whether this variant is PathType::File.

Trait Implementations§

source§

impl AsRef<OsStr> for PathType

source§

fn as_ref(&self) -> &OsStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Path> for PathType

source§

fn as_ref(&self) -> &Path

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<PathAbs> for PathType

source§

fn as_ref(&self) -> &PathAbs

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<PathBuf> for PathType

source§

fn as_ref(&self) -> &PathBuf

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Borrow<Path> for &'a PathType

source§

fn borrow(&self) -> &Path

Immutably borrows from an owned value. Read more
source§

impl Borrow<Path> for PathType

source§

fn borrow(&self) -> &Path

Immutably borrows from an owned value. Read more
source§

impl<'a> Borrow<PathAbs> for &'a PathType

source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
source§

impl Borrow<PathAbs> for PathType

source§

fn borrow(&self) -> &PathAbs

Immutably borrows from an owned value. Read more
source§

impl<'a> Borrow<PathBuf> for &'a PathType

source§

fn borrow(&self) -> &PathBuf

Immutably borrows from an owned value. Read more
source§

impl Borrow<PathBuf> for PathType

source§

fn borrow(&self) -> &PathBuf

Immutably borrows from an owned value. Read more
source§

impl Clone for PathType

source§

fn clone(&self) -> PathType

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PathType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<PathType> for Arc<PathBuf>

source§

fn from(path: PathType) -> Arc<PathBuf>

Converts to this type from the input type.
source§

impl From<PathType> for PathAbs

source§

fn from(path: PathType) -> PathAbs

Converts to this type from the input type.
source§

impl From<PathType> for PathBuf

source§

fn from(path: PathType) -> PathBuf

Converts to this type from the input type.
source§

impl Hash for PathType

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

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

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for PathType

source§

fn cmp(&self, other: &PathType) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<PathType> for PathType

source§

fn eq(&self, other: &PathType) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<PathType> for PathType

source§

fn partial_cmp(&self, other: &PathType) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PathOps for PathType

§

type Output = PathAbs

source§

fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>

Returns a new value representing the concatenation of two paths. Read more
source§

fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output

An exact replica of std::path::Path::join with all of its gotchas and pitfalls,, except returns a more relevant type. Read more
source§

fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output

Creates a new path object like self but with the given file name. Read more
source§

fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output

Creates a new path object like self but with the given extension. Read more
source§

impl Eq for PathType

source§

impl StructuralEq for PathType

source§

impl StructuralPartialEq for PathType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> PathInfo for Twhere T: Clone + Borrow<PathBuf> + Into<Arc<PathBuf>>,

source§

fn as_path(&self) -> &Path

source§

fn to_arc_pathbuf(&self) -> Arc<PathBuf>

source§

fn as_os_str(&self) -> &OsStr

source§

fn to_str(&self) -> Option<&str>

source§

fn to_string_lossy(&self) -> Cow<'_, str>

source§

fn is_absolute(&self) -> bool

source§

fn is_relative(&self) -> bool

source§

fn has_root(&self) -> bool

source§

fn ancestors(&self) -> Ancestors<'_>

source§

fn file_name(&self) -> Option<&OsStr>

source§

fn strip_prefix<P>(&self, base: P) -> Result<&Path, StripPrefixError>where P: AsRef<Path>,

source§

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

source§

fn ends_with<P: AsRef<Path>>(&self, base: P) -> bool

source§

fn file_stem(&self) -> Option<&OsStr>

source§

fn extension(&self) -> Option<&OsStr>

source§

fn components(&self) -> Components<'_>

source§

fn iter(&self) -> Iter<'_>

source§

fn display(&self) -> Display<'_>

source§

fn metadata(&self) -> Result<Metadata>

Queries the file system to get information about a file, directory, etc. Read more
Queries the metadata about a file without following symlinks. Read more
source§

fn exists(&self) -> bool

source§

fn is_file(&self) -> bool

source§

fn is_dir(&self) -> bool

Reads a symbolic link, returning the path that the link points to. Read more
source§

fn canonicalize(&self) -> Result<PathAbs>

Returns the canonical, absolute form of the path with all intermediate components normalized and symbolic links resolved. Read more
source§

fn parent(&self) -> Result<&Path>

Returns the path without its final component, if there is one. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.