-
In something like: seq! {
Frame {
kind: be_u8.map(PacketKind::from),
stuff: be_u16,
packet: parse_packet(kind), // ???
}
}.parse_next(i)
enum Packet {
One { .. },
Two { .. },
} It doesn't seem to be possible with a parser like: pub fn parse_packet(i: &mut Stream, kind: PacketKind) -> PResult<Packet> The only way I have found is: pub fn parse_packet(kind: PacketKind) -> impl FnMut(&mut Stream) -> PResult<Packet> and have it return the right parser based on Am I missing an easier way? Thanks! BackgroundThe protocols we parse often have different subtypes defined in a field (like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Sounds like you are doing pub fn parse_packet(kind: PacketKind) -> impl Parser<Stream, Package, ContextError> {
match kind {
// ...
}
} but you can also do pub fn parse_packet(kind: PacketKind) -> impl Parser<Stream, Package, ContextError> {
|stream| parse_package(stream, kind)
}
fn parse_packet_(i: &mut Stream, kind: PacketKind) -> PResult<Packet> |
Beta Was this translation helpful? Give feedback.
Sounds like you are doing
but you can also do