Skip to content

Pass extra argument to parser inside seq!? #547

Answered by epage
ckoehler asked this question in Q&A
Discussion options

You must be logged in to vote

and have it return the right parser based on PacketKind. This adds a bit more overhead, since now I need a match or something to get to the right parser, whereas the first would allow me to just return the right type immediately.

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>

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ckoehler
Comment options

@epage
Comment options

@ckoehler
Comment options

Answer selected by ckoehler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants