Closed rneswold closed 3 years ago
I found StreamErrorFor
. Doing some investigating ...
Sorry for the noise. The Wiki example makes the code compile.
For anyone who comes across this and doesn't quite understand StreamErrorFor
(like I didn't)... It's essentially a type alias to help name an error which should satisfy some traits. It looks like you use it like this:
fn cc<I>() -> impl Parser<I, Output = PacketType>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
StreamErrorFor<I>: From<UnexpectedParse>,
{
digit().and_then(|cc| PacketType::try_from(cc).map_err(|_| UnexpectedParse::Unexpected))
}
As opposed to what the compiler tells you to do:
fn cc<I>() -> impl Parser<I, Output = PacketType>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
- StreamErrorFor<I>: From<UnexpectedParse>,
+ <<I as StreamOnce>::Error as ParseError<
+ char,
+ <I as StreamOnce>::Range,
+ <I as StreamOnce>::Position,
+ >>::StreamError: From<UnexpectedParse>,
{
digit().and_then(|cc| PacketType::try_from(cc).map_err(|_| UnexpectedParse::Unexpected))
}
I've been having good, initial success using
combine
but I've reached a point where I need to report an error if an integer field is out of range. The function isThis generates errors since
ParseIntError
can't be converted to aStreamError
. I try some of the recommendations offered by the compiler but those also return errors. The project's Wiki page mentions ways of reporting errors, but it seems to be out-of-date since it mentionsStreamErrorFor::<>
which I couldn't find in the docs.Am I trying too hard? Is there a straightforward way of reporting errors that I'm missing?
Can the Wiki be brought up to date?