pub struct Error { /* private fields */ }
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
impl Error
Sourcepub fn path(&self) -> Option<&Path>
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
.
Sourcepub fn loop_ancestor(&self) -> Option<&Path>
pub fn loop_ancestor(&self) -> Option<&Path>
Sourcepub fn io_error(&self) -> Option<&Error>
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 asimpl 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)
}
}
}
}
}
}
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Source§fn description(&self) -> &str
fn description(&self) -> &str
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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