Struct path_abs::PathDir [] [src]

pub struct PathDir(_);

A PathAbs that is guaranteed to be a directory, with associated methods.

Methods

impl PathDir
[src]

[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").unwrap();

[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").unwrap();
let src_dir = PathDir::from_abs(src_abs).unwrap();

[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).unwrap();

// It can be done twice with no effect.
let _ = PathDir::create(example).unwrap();

[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).unwrap();

// It can be done twice with no effect.
let _ = PathDir::create_all(example).unwrap();

[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").unwrap();
let lib = src.join_abs("lib.rs").unwrap().unwrap_file();
assert!(lib.is_file());

[src]

List the contents of the directory, returning an iterator of PathTypes.

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).unwrap();
let foo_dir = PathDir::create(example_dir.join("foo")).unwrap();
let bar_file = PathFile::create(example_dir.join("bar.txt")).unwrap();

let mut result = HashSet::new();
for p in example_dir.list().unwrap() {
    result.insert(p.unwrap());
}

let mut expected = HashSet::new();
expected.insert(PathType::Dir(foo_dir));
expected.insert(PathType::File(bar_file));

assert_eq!(expected, 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).unwrap();
let parent = dir.parent_dir().unwrap();

assert!(example.exists());
dir.remove().unwrap();
// assert!(dir.exists());  <--- COMPILE ERROR
assert!(!example.exists());
parent.remove().unwrap();

[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).unwrap();
let parent = dir.parent_dir().unwrap();

assert!(example.exists());
parent.remove_all().unwrap();
assert!(!example.exists());

[src]

Create a mock dir type. For use in tests only.

See the docs for PathAbs::mock

Methods from Deref<Target = PathAbs>

[src]

Resolve the PathAbs as a PathFile. Return an error if it is not a file.

[src]

Resolve the PathAbs as a PathDir. Return an error if it is not a directory.

[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").unwrap();
let src = lib.parent_dir().unwrap();
assert_eq!(PathDir::new("src").unwrap(), src);

Trait Implementations

impl Clone for PathDir
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for PathDir
[src]

impl Hash for PathDir
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

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

impl PartialEq for PathDir
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl PartialOrd for PathDir
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[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]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl Debug for PathDir
[src]

[src]

Formats the value using the given formatter.

impl AsRef<PathAbs> for PathDir
[src]

[src]

Performs the conversion.

impl AsRef<Path> for PathDir
[src]

[src]

Performs the conversion.

impl AsRef<PathBuf> for PathDir
[src]

[src]

Performs the conversion.

impl Deref for PathDir
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl Into<PathAbs> for PathDir
[src]

[src]

Performs the conversion.

impl Serialize for PathDir
[src]

[src]

Serialize this value into the given Serde serializer. Read more

impl<'de> Deserialize<'de> for PathDir
[src]

[src]

Deserialize this value from the given Serde deserializer. Read more