Struct Error
struct Error { ... }
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
impl Error
fn path(self: &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.fn loop_ancestor(self: &Self) -> Option<&Path>Returns the path at which a cycle was detected.
If no cycle was detected,
Noneis 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
pathmethod.fn depth(self: &Self) -> usizeReturns the depth at which this error occurred relative to the root.
The smallest depth is
0and always corresponds to the path given to thenewfunction onWalkDir. Its direct descendents have depth1, and their descendents have depth2, and so on.fn io_error(self: &Self) -> Option<&Error>Inspect the original
io::Errorif there is one.Noneis returned if theErrordoesn't correspond to anio::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, theinto_io_errorcan be used instead.This is the original
io::Errorand is not the same asimpl From<Error> for std::io::Errorwhich contains additional context about the error.Example
use io; use Path; use WalkDir; for entry in newfn into_io_error(self: Self) -> Option<Error>Similar to
io_errorexcept consumes self to convert to the originalio::Errorif one exists.
impl Debug for Error
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Display for Error
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Error for Error
fn description(self: &Self) -> &strfn cause(self: &Self) -> Option<&dyn Error>fn source(self: &Self) -> Option<&dyn Error + 'static>
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
impl<T> Any for Error
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Error
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Error
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Error
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToString for Error
fn to_string(self: &Self) -> String
impl<T, U> Into for Error
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Error
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Error
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>