-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add map functions for Error<> and Info<> ranges. (#86) #87
Conversation
It's possible to `map_err_range` for `ParseResult<>` too, but it's awkward because the output type needs to be a compatible `StreamOnce`. As suggested in Marwes#86 (comment), it's probably best to either change the parse result type entirely, or wait for rust-lang/rust#21903. This at least helps consumers convert `ParseError<>` into something that can implement `std::fmt::Display`.
@Marwes as I say, I'm okay with pushing this into Mentat if you don't feel it's appropriate. I'm not 100% sure that's possible though, since the enums are |
Owned(s) => Owned(s), | ||
Borrowed(x) => Borrowed(x), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a map_token
function as well?
src/primitives.rs
Outdated
@@ -110,6 +122,18 @@ pub enum Error<T, R> { | |||
Other(Box<StdError + Send + Sync>), | |||
} | |||
|
|||
impl<T, R> Error<T, R> { | |||
pub fn map_err_range<F, S>(self, f: F) -> Error<T, S> where F: FnOnce(R) -> S { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is enough to call this map_range
.
Message(x) => Message(x.map_range(f)), | ||
Other(x) => Other(x), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ map_token
With branches, do you mean enum variants ( |
@Marwes I added follow-up to address your review comment, and thought I might as well make it easy for the next poor fool to copy-paste the conversion to |
Failing on the rust 1.11 test on travis. I am not to attached to preserving backwards functionality but prefixing the |
Managed to push to this PR so it should be fixed after travis finishes. |
@Marwes could you push a release including this sometime soon? Thanks! |
I will, just want to add some more docs for #85. |
Just released 2.3.0 |
Many thanks, @Marwes! |
It's possible to
map_err_range
forParseResult<>
too, but it'sawkward because the output type needs to be a compatible
StreamOnce
.As suggested in
#86 (comment),
it's probably best to either change the parse result type entirely, or
wait for rust-lang/rust#21903.
This at least helps consumers convert
ParseError<>
into somethingthat can implement
std::fmt::Display
.