Struct path_abs::PathDir
[−]
[src]
pub struct PathDir(_);
A PathAbs
that is guaranteed to be a directory, with associated methods.
Methods
impl PathDir
[src]
fn new<P: AsRef<Path>>(path: P) -> Result<PathDir>
[src]
Instantiate a new PathDir
. The directory must exist or io::Error
will be returned.
Returns io::ErrorKind::InvalidInput
if the path exists but is not a directory.
Examples
use path_abs::PathDir; let src = PathDir::new("src")?;
fn from_abs(abs: PathAbs) -> Result<PathDir>
[src]
Consume the PathAbs
validating that the path is a directory and returning PathDir
. The
directory must exist or io::Error
will be returned.
If the path is actually a file returns io::ErrorKind::InvalidInput
.
This does not call
Path::cannonicalize()
, instead trusting that the input is already a fully qualified path.
Examples
use path_abs::{PathAbs, PathDir}; let src_abs = PathAbs::new("src")?; let src_dir = PathDir::from_abs(src_abs)?;
fn from_abs_unchecked(abs: PathAbs) -> PathDir
[src]
Do the conversion without checking.
This is typically used by external libraries when the type is already known through some other means (to avoid a syscall).
fn create<P: AsRef<Path>>(path: P) -> Result<PathDir>
[src]
Instantiate a new PathDir
to a directory, creating the directory if it doesn't exist.
Examples
use path_abs::PathDir; let example = "example"; let dir = PathDir::create(example)?; // It can be done twice with no effect. let _ = PathDir::create(example)?;
fn create_all<P: AsRef<Path>>(path: P) -> Result<PathDir>
[src]
Instantiate a new PathDir
to a directory, recursively recreating it and all of its parent
components if they are missing.
Examples
use path_abs::PathDir; let example = "example/long/path"; let path = PathDir::create_all(example)?; // It can be done twice with no effect. let _ = PathDir::create_all(example)?;
fn join_abs<P: AsRef<Path>>(&self, path: P) -> Result<PathType>
[src]
Join a path onto the PathDir
, expecting it to exist. Returns the resulting PathType
.
Examples
use path_abs::{PathDir, PathFile}; let src = PathDir::new("src")?; let lib = src.join_abs("lib.rs")?.unwrap_file(); assert!(lib.is_file());
fn list(&self) -> Result<ListDir>
[src]
List the contents of the directory, returning an iterator of PathType
s.
Warning: because
PathAbs
is the canonicalized path, symlinks are always resolved. This means that if the directory contains a symlink you may get a path from a completely different directory.
Examples
use std::collections::HashSet; use path_abs::{PathDir, PathFile, PathType}; let example = "example"; let example_dir = PathDir::create(example)?; let foo_dir = PathDir::create(example_dir.join("foo"))?; let bar_file = PathFile::create(example_dir.join("bar.txt"))?; let mut result = HashSet::new(); for p in example_dir.list()? { result.insert(p?); } let mut expected = HashSet::new(); expected.insert(PathType::Dir(foo_dir)); expected.insert(PathType::File(bar_file)); assert_eq!(expected, result);
fn remove(self) -> Result<()>
[src]
Remove (delete) the empty directory from the filesystem, consuming self.
Examples
use std::path::Path; use path_abs::PathDir; let example = Path::new("example/long/path"); let dir = PathDir::create_all(example)?; let parent = dir.parent_dir().unwrap(); assert!(example.exists()); dir.remove()?; // assert!(dir.exists()); <--- COMPILE ERROR assert!(!example.exists()); parent.remove()?;
fn remove_all(self) -> Result<()>
[src]
Remove (delete) the directory, after recursively removing its contents. Use carefully!
Examples
use std::path::Path; use path_abs::PathDir; let example = Path::new("example/long/path"); let dir = PathDir::create_all(example)?; let parent = dir.parent_dir().unwrap(); assert!(example.exists()); parent.remove_all()?; assert!(!example.exists());
fn as_path(&self) -> &Path
[src]
Return a reference to a basic std::path::Path
fn mock<P: AsRef<Path>>(path: P) -> PathDir
[src]
Create a mock dir type. For use in tests only.
See the docs for PathAbs::mock
Methods from Deref<Target = PathAbs>
fn into_file(self) -> Result<PathFile>
[src]
Resolve the PathAbs
as a PathFile
. Return an error if it is not a file.
fn into_dir(self) -> Result<PathDir>
[src]
Resolve the PathAbs
as a PathDir
. Return an error if it is not a directory.
fn parent_dir(&self) -> Option<PathDir>
[src]
Get the parent directory of this path as a PathDir
.
This does not make aditional syscalls, as the parent by definition must be a directory and exist.
Examples
use path_abs::{PathDir, PathFile}; let lib = PathFile::new("src/lib.rs")?; let src = lib.parent_dir().unwrap(); assert_eq!(PathDir::new("src")?, src);
fn as_path(&self) -> &Path
[src]
Return a reference to a basic std::path::Path
Trait Implementations
impl Clone for PathDir
[src]
fn clone(&self) -> PathDir
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for PathDir
[src]
impl Hash for PathDir
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for PathDir
[src]
fn eq(&self, __arg_0: &PathDir) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &PathDir) -> bool
[src]
This method tests for !=
.
impl PartialOrd for PathDir
[src]
fn partial_cmp(&self, __arg_0: &PathDir) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &PathDir) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &PathDir) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &PathDir) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &PathDir) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for PathDir
[src]
fn cmp(&self, __arg_0: &PathDir) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl Debug for PathDir
[src]
impl AsRef<PathAbs> for PathDir
[src]
impl AsRef<PathArc> for PathDir
[src]
impl AsRef<Path> for PathDir
[src]
impl AsRef<PathBuf> for PathDir
[src]
impl Borrow<PathAbs> for PathDir
[src]
impl Borrow<PathArc> for PathDir
[src]
impl Borrow<Path> for PathDir
[src]
impl Borrow<PathBuf> for PathDir
[src]
impl<'a> Borrow<PathAbs> for &'a PathDir
[src]
impl<'a> Borrow<PathArc> for &'a PathDir
[src]
impl<'a> Borrow<Path> for &'a PathDir
[src]
impl<'a> Borrow<PathBuf> for &'a PathDir
[src]
impl Deref for PathDir
[src]
type Target = PathAbs
The resulting type after dereferencing.
fn deref(&self) -> &PathAbs
[src]
Dereferences the value.
impl Into<PathAbs> for PathDir
[src]
fn into(self) -> PathAbs
[src]
Downgrades the PathDir
into a PathAbs
Examples
use std::path::PathBuf; use path_abs::{PathDir, PathAbs}; let dir = PathDir::new("src")?; let abs: PathAbs = dir.into();
impl Into<PathArc> for PathDir
[src]
impl Into<PathBuf> for PathDir
[src]
fn into(self) -> PathBuf
[src]
Downgrades the PathDir
into a PathBuf
. Avoids a clone if this is the only reference.
Examples
use path_abs::PathDir; use std::path::PathBuf; let dir = PathDir::new("src")?; let buf: PathBuf = dir.into();
impl Serialize for PathDir
[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
[src]
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for PathDir
[src]
fn deserialize<D>(deserializer: D) -> Result<PathDir, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more