BurntSushi / walkdir

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

add example for converting to I/O error #82

Closed nivkner closed 6 years ago

nivkner commented 6 years ago

fixes #81

KodrAus commented 6 years ago

Thanks @nivkner! I like the idea of offering an io_error method on walkdir's Error type that returns &io::Error. It might be a bit clearer and more compact than From::from in cases where you just want to inspect part of the error.

What do you think?

nivkner commented 6 years ago

I think it's a good idea since you probably don't want to consume the error just to check the io::Error.

However, I did make one change: return Option<&io::Error> since there is the case where Error doesn't represent an I/O error but rather a cycle.

Unlike From where you could just construct a new error, here the return value must be a borrow, where I have nothing to borrow.

Returning something new as a borrow just results in does not live long enough error.

nivkner commented 6 years ago

Fixed the PR as per @BurntSushi's review.