BurntSushi / walkdir

Rust library for walking directories recursively.
The Unlicense
1.22k stars 107 forks source link

add example for extracting the underlying I/O error #81

Closed BurntSushi closed 6 years ago

BurntSushi commented 6 years ago

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.

pwil3058 commented 6 years ago

That does solve my problem: io::Error::from(err)..kind() gives me an ErrorKind. Thanks.