Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upadd example for converting to I/O error #82
Conversation
nivkner
force-pushed the
nivkner:from_err
branch
5 times, most recently
from
e511bb6
to
78d0c68
Sep 22, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks @nivkner! I like the idea of offering an What do you think? |
nivkner
force-pushed the
nivkner:from_err
branch
from
78d0c68
to
a149b49
Oct 1, 2017
This comment has been minimized.
This comment has been minimized.
|
I think it's a good idea since you probably don't want to consume the error just to check the However, I did make one change: return Unlike Returning something new as a borrow just results in |
nivkner
force-pushed the
nivkner:from_err
branch
3 times, most recently
from
d5f0822
to
9a9fb47
Oct 1, 2017
KodrAus
reviewed
Oct 2, 2017
|
This is looking good! Thanks @nivkner. I'd like to know what you and @BurntSushi think about using |
| /// | ||
| /// [`None`]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#variant.None | ||
| /// [`io::Error`]: https://doc.rust-lang.org/stable/std/io/struct.Error.html | ||
| pub fn io_error(&self) -> Option<&io::Error> { |
This comment has been minimized.
This comment has been minimized.
KodrAus
Oct 2, 2017
Contributor
I wonder if this could be a Cow<'a, io::Error>? Then you could always return an error, but if it's not already an io::Error then you'll get Cow::Owned.
You should just be able to match on err.io_error().kind() then.
This comment has been minimized.
This comment has been minimized.
nivkner
Oct 2, 2017
•
Author
Contributor
That would be great, except for the fact that to do that, io::Error needs to implement ToOwned to be enclosed in Cow, which it doesn't.
This comment has been minimized.
This comment has been minimized.
| @@ -1277,6 +1277,44 @@ impl Error { | |||
| self.depth | |||
| } | |||
|
|
|||
| /// Inspect the underlying [`io::Error`] if there is one. | |||
| /// If a cycle was detected instead, [`None`] is returned. | |||
This comment has been minimized.
This comment has been minimized.
KodrAus
Oct 2, 2017
Contributor
I would just say here that if the underlying error isn't an io::Error than the result is None. My other comment might make this obsolete though.
nivkner
force-pushed the
nivkner:from_err
branch
from
9a9fb47
to
dde9279
Oct 2, 2017
BurntSushi
requested changes
Oct 2, 2017
|
Overall this looks great! Thanks for helping to improve the documentation. :-) I added a bunch of mostly stylistic nits that I hope we can fix before merging. |
| /// [`io::Error`]: https://doc.rust-lang.org/stable/std/io/struct.Error.html | ||
| pub fn io_error(&self) -> Option<&io::Error> { | ||
| match self.inner { | ||
| ErrorInner::Io { path: _ , ref err } => Some(err), |
This comment has been minimized.
This comment has been minimized.
BurntSushi
Oct 2, 2017
Owner
You don't need to mention path here since you aren't using it. This should work: ErrorInner::Io { ref err, .. }.
| /// continue | ||
| /// } | ||
| /// }; | ||
| /// println!("{}", entry.path().display()); |
This comment has been minimized.
This comment has been minimized.
BurntSushi
Oct 2, 2017
Owner
I feel like the let entry = ... here is unnecessary. Maybe just move the println! into the match expression arm?
| /// | ||
| /// let mut it = WalkDir::new("foo").into_iter(); | ||
| /// loop { | ||
| /// let entry = match it.next() { |
This comment has been minimized.
This comment has been minimized.
BurntSushi
Oct 2, 2017
Owner
Could you please reformat this code so that it fits into 79 columns inclusive?
| /// If the underlying error isn't an [`io::Error`], [`None`] is returned. | ||
| /// | ||
| /// ```rust,no-run | ||
| /// use walkdir::{WalkDir}; |
This comment has been minimized.
This comment has been minimized.
| /// use std::path::Path; | ||
| /// | ||
| /// let mut it = WalkDir::new("foo").into_iter(); | ||
| /// loop { |
This comment has been minimized.
This comment has been minimized.
| @@ -1277,6 +1277,44 @@ impl Error { | |||
| self.depth | |||
| } | |||
|
|
|||
| /// Inspect the underlying [`io::Error`] if there is one. | |||
| /// If the underlying error isn't an [`io::Error`], [`None`] is returned. | |||
This comment has been minimized.
This comment has been minimized.
BurntSushi
Oct 2, 2017
Owner
Could the documentation be expanded to mention when this might not contain an io::Error? e.g., "In some circumstances, this Error won't correspond to an io::Error, for example, when the error was produced because a cycle was found in the directory tree while following symbolic links."
This comment has been minimized.
This comment has been minimized.
BurntSushi
Oct 2, 2017
Owner
I think the docs should also mention that if the caller wants to acquire an owned io::Error, then they can convert this error into an io::Error using io::Error::from(err). And state that if this error doesn't correspond to an io::Error, then one is created.
| @@ -1277,6 +1277,44 @@ impl Error { | |||
| self.depth | |||
| } | |||
|
|
|||
| /// Inspect the underlying [`io::Error`] if there is one. | |||
This comment has been minimized.
This comment has been minimized.
nivkner
force-pushed the
nivkner:from_err
branch
4 times, most recently
from
50be3b8
to
dbadf08
Oct 4, 2017
nivkner
force-pushed the
nivkner:from_err
branch
from
dbadf08
to
8cdb7e5
Oct 7, 2017
This comment has been minimized.
This comment has been minimized.
|
Fixed the PR as per @BurntSushi's review. |
nivkner commentedSep 22, 2017
fixes #81