You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a type both implements the Parse trait, and has another parse function implemented directly, the generated code in nom-derive seems to prefer the direct parse function, even if the signature of it doesn't match.
Context
I was trying to parse a value-only enum, but with a twist that the remaining values should all go into an Unassigned enum that stores the value. I am using the Selector derived parse, but also provide a nom_derive::Parse trait implementation. The code looks roughly like the following:
However, when nesting this inside another struct, the generated code fails, because the parse function it found expects two arguments, instead of one, even though I implemented the Parse trait that has the correct signature.
#[derive(Nom,Debug)]pubstructFileHeader<'a>{#[nom(Verify = "*version == 1")]pubversion:u32,/// The datalink type for the packet records that follow.pubdatalink_type:DatalinkType,}
I had to add #[nom(Parse = "<DatalinkType as Parse<_>>::parse")] to get it to use the parse trait. Not sure if you would consider that a bug, but that behavior felt surprising to me, and I think it would be nice if it prefers the implementation from the Parse trait rather than trying to use an incompatible one.
If a type both implements the
Parse
trait, and has anotherparse
function implemented directly, the generated code in nom-derive seems to prefer the directparse
function, even if the signature of it doesn't match.Context
I was trying to parse a value-only enum, but with a twist that the remaining values should all go into an
Unassigned
enum that stores the value. I am using theSelector
derivedparse
, but also provide anom_derive::Parse
trait implementation. The code looks roughly like the following:However, when nesting this inside another struct, the generated code fails, because the
parse
function it found expects two arguments, instead of one, even though I implemented theParse
trait that has the correct signature.I had to add
#[nom(Parse = "<DatalinkType as Parse<_>>::parse")]
to get it to use the parse trait. Not sure if you would consider that a bug, but that behavior felt surprising to me, and I think it would be nice if it prefers the implementation from theParse
trait rather than trying to use an incompatible one.My complete code is here: https://github.com/mauricelam/btsnoop-rs/pull/12/files
The text was updated successfully, but these errors were encountered: