Struct ergo_fs::PathDir
[−]
[src]
pub struct PathDir(_);
A PathAbs
that is guaranteed to be a directory, with associated methods.
Methods
impl PathDir
[src]
fn new<P>(path: P) -> Result<PathDir, Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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, Error>
[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>(path: P) -> Result<PathDir, Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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>(path: P) -> Result<PathDir, Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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>(&self, path: P) -> Result<PathType, Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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, Error>
[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<(), Error>
[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<(), Error>
[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>(path: P) -> PathDir where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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, Error>
[src]
Resolve the PathAbs
as a PathFile
. Return an error if it is not a file.
fn into_dir(self) -> Result<PathDir, Error>
[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 Serialize for PathDir
[src]
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
[src]
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
impl Ord for PathDir
[src]
impl Hash for PathDir
[src]
fn hash<__H>(&self, __arg_0: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
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 Clone for PathDir
[src]
impl Eq for PathDir
[src]
impl Deref for PathDir
[src]
type Target = PathAbs
The resulting type after dereferencing.
fn deref(&self) -> &PathAbs
[src]
Dereferences the value.
impl AsRef<PathAbs> for PathDir
[src]
impl AsRef<Path> for PathDir
[src]
impl AsRef<PathBuf> for PathDir
[src]
impl PartialEq<PathDir> for PathDir
[src]
impl Debug for PathDir
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<'de> Deserialize<'de> for PathDir
[src]
fn deserialize<D>(
deserializer: D
) -> Result<PathDir, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
[src]
deserializer: D
) -> Result<PathDir, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
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<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();