The Error type that walkdir exposes is a light wrapper around a std::io::Error. The purpose of the custom error type is to provide better error messages by default (for example, by including the file path name that caused a specific error). However, it is sometimes desirable to access the underlying I/O error. While there is no concrete method for accessing the underlying I/O error, one can convert a walkdir::Error into a std::io::Error using io::Error::from(err) where err is a walkdir::Error. This is because walkdir provides a impl From<walkdir::Error> for std::io::Error.
Once you have a std::io::Error, you could then extract its ErrorKind and do case analysis there.
It would be nice to have an example for this. We might also consider adding an io_error method that returns a &std::io::Error.
The
Error
type thatwalkdir
exposes is a light wrapper around astd::io::Error
. The purpose of the custom error type is to provide better error messages by default (for example, by including the file path name that caused a specific error). However, it is sometimes desirable to access the underlying I/O error. While there is no concrete method for accessing the underlying I/O error, one can convert awalkdir::Error
into astd::io::Error
usingio::Error::from(err)
whereerr
is awalkdir::Error
. This is becausewalkdir
provides aimpl From<walkdir::Error> for std::io::Error
.Once you have a
std::io::Error
, you could then extract itsErrorKind
and do case analysis there.It would be nice to have an example for this. We might also consider adding an
io_error
method that returns a&std::io::Error
.