gix_features::fs::walkdir

Struct Error

Source
pub struct Error { /* private fields */ }
Available on crate feature fs-walkdir-parallel only.
Expand description

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:

  • The depth at which the error occurred in the file tree, relative to the root.
  • The path, if any, associated with the IO error.
  • An indication that a loop occurred when following symbolic links. In this case, there is no underlying IO error.

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§

Source§

impl Error

Source

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

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.

Source

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

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.

Source

pub fn depth(&self) -> usize

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 descendants have depth 1, and their descendants have depth 2, and so on.

Source

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

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)
                    }
                }
            }
        }
    }
}
Source

pub fn is_busy(&self) -> bool

Returns true if this error is due to a busy thread-pool that prevented its effective use.

Note that business detection is timeout based, and we don’t know if it would have been a deadlock or not.

Source

pub fn into_io_error(self) -> Option<Error>

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

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.