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
impl PathType
sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<PathType>
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")?;
sourcepub fn try_from<P: Into<PathAbs>>(path: P) -> Result<PathType>
pub fn try_from<P: Into<PathAbs>>(path: P) -> Result<PathType>
Consume the PathAbs
returning the PathType
.
sourcepub fn unwrap_file(self) -> PathFile
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();
sourcepub fn unwrap_dir(self) -> PathDir
pub fn unwrap_dir(self) -> PathDir
Unwrap the PathType
as a PathDir
.
Examples
use path_abs::PathType;
let src = PathType::new("src")?.unwrap_dir();
Trait Implementations§
source§impl Ord for PathType
impl Ord for PathType
source§impl PartialEq<PathType> for PathType
impl PartialEq<PathType> for PathType
source§impl PartialOrd<PathType> for PathType
impl PartialOrd<PathType> for PathType
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PathOps for PathType
impl PathOps for PathType
type Output = PathAbs
source§fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>
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
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 moreimpl Eq for PathType
impl StructuralEq for PathType
impl StructuralPartialEq for PathType
Auto Trait Implementations§
impl RefUnwindSafe for PathType
impl Send for PathType
impl Sync for PathType
impl Unpin for PathType
impl UnwindSafe for PathType
Blanket Implementations§
source§impl<T> PathInfo for Twhere
T: Clone + Borrow<PathBuf> + Into<Arc<PathBuf>>,
impl<T> PathInfo for Twhere T: Clone + Borrow<PathBuf> + Into<Arc<PathBuf>>,
fn as_path(&self) -> &Path
fn to_arc_pathbuf(&self) -> Arc<PathBuf>
fn as_os_str(&self) -> &OsStr
fn to_str(&self) -> Option<&str>
fn to_string_lossy(&self) -> Cow<'_, str>
fn is_absolute(&self) -> bool
fn is_relative(&self) -> bool
fn has_root(&self) -> bool
fn ancestors(&self) -> Ancestors<'_>
fn file_name(&self) -> Option<&OsStr>
fn strip_prefix<P>(&self, base: P) -> Result<&Path, StripPrefixError>where P: AsRef<Path>,
fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool
fn ends_with<P: AsRef<Path>>(&self, base: P) -> bool
fn file_stem(&self) -> Option<&OsStr>
fn extension(&self) -> Option<&OsStr>
fn components(&self) -> Components<'_>
fn iter(&self) -> Iter<'_>
fn display(&self) -> Display<'_>
source§fn metadata(&self) -> Result<Metadata>
fn metadata(&self) -> Result<Metadata>
Queries the file system to get information about a file, directory, etc. Read more
source§fn symlink_metadata(&self) -> Result<Metadata>
fn symlink_metadata(&self) -> Result<Metadata>
Queries the metadata about a file without following symlinks. Read more
fn exists(&self) -> bool
fn is_file(&self) -> bool
fn is_dir(&self) -> bool
source§fn read_link(&self) -> Result<PathBuf>
fn read_link(&self) -> Result<PathBuf>
Reads a symbolic link, returning the path that the link points to. Read more