Struct walkdir::Error[][src]

pub struct Error { /* fields omitted */ }

An error produced by recursively walking a directory.

This error type is a light wrapper around std::io::Error. In particular, it adds the following information:

To maintain good ergonomics, this type has a impl From<Error> for std::io::Error defined which preserves the original context. This allows you to use an io::Result with methods in this crate if you don’t care about accessing the underlying error data in a structured form.

Implementations

impl Error[src]

pub fn path(&self) -> Option<&Path>[src]

Returns the path associated with this error if one exists.

For example, if an error occurred while opening a directory handle, the error will include the path passed to std::fs::read_dir.

pub fn loop_ancestor(&self) -> Option<&Path>[src]

Returns the path at which a cycle was detected.

If no cycle was detected, None is returned.

A cycle is detected when a directory entry is equivalent to one of its ancestors.

To get the path to the child directory entry in the cycle, use the path method.

pub fn depth(&self) -> usize[src]

Returns the depth at which this error occurred relative to the root.

The smallest depth is 0 and always corresponds to the path given to the new function on WalkDir. Its direct descendents have depth 1, and their descendents have depth 2, and so on.

pub fn io_error(&self) -> Option<&Error>[src]

Inspect the original io::Error if there is one.

None is returned if the Error doesn’t correspond to an io::Error. This might happen, for example, when the error was produced because a cycle was found in the directory tree while following symbolic links.

This method returns a borrowed value that is bound to the lifetime of the Error. To obtain an owned value, the into_io_error can be used instead.

This is the original io::Error and is not the same as impl From<Error> for std::io::Error which contains additional context about the error.

Example

use std::io;
use std::path::Path;

use walkdir::WalkDir;

for entry in WalkDir::new("foo") {
    match entry {
        Ok(entry) => println!("{}", entry.path().display()),
        Err(err) => {
            let path = err.path().unwrap_or(Path::new("")).display();
            println!("failed to access entry {}", path);
            if let Some(inner) = err.io_error() {
                match inner.kind() {
                    io::ErrorKind::InvalidData => {
                        println!(
                            "entry contains invalid data: {}",
                            inner)
                    }
                    io::ErrorKind::PermissionDenied => {
                        println!(
                            "Missing permission to read entry: {}",
                            inner)
                    }
                    _ => {
                        println!(
                            "Unexpected error occurred: {}",
                            inner)
                    }
                }
            }
        }
    }
}

pub fn into_io_error(self) -> Option<Error>[src]

Similar to io_error except consumes self to convert to the original io::Error if one exists.

Trait Implementations

impl Debug for Error[src]

impl Display for Error[src]

impl Error for Error[src]

impl From<Error> for Error[src]

fn from(walk_err: Error) -> Error[src]

Convert the Error to an io::Error, preserving the original Error as the “inner error”. Note that this also makes the display of the error include the context.

This is different from into_io_error which returns the original io::Error.

Auto Trait Implementations

impl !RefUnwindSafe for Error

impl Send for Error

impl Sync for Error

impl Unpin for Error

impl !UnwindSafe for Error

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.