jam1garner / binrw

A Rust crate for helping parse and rebuild binary data using ✨macro magic✨.
https://binrw.rs
MIT License
545 stars 35 forks source link

map_stream, parse_with and args together fail to compile #240

Closed himikof closed 7 months ago

himikof commented 7 months ago

Notice the following line in the example from #217:

    #[br(map_stream = |s| s.take_seek(16), parse_with = |r, e, _:()| until_eof(r, e, (v,)))]

I expect there to be a simpler way to achieve this:

    #[br(map_stream = |s| s.take_seek(16), parse_with = until_eof, args(v))]

Surprisingly, this fails to compile:

error[E0308]: mismatched types
   --> src/test.rs:46:9
    |
461 |     #[derive(Debug, BinRead)]
    |                     ------- this type parameter
...
467 |         #[br(map_stream = |s| s.take_seek(16), parse_with = helpers::until_eof, args(v))]
    |                                                             ------- arguments to this function are incorrect
468 |         data: Vec<Thing>,
    |         ^^^^ expected `&mut R`, found `&mut TakeSeek<&mut R>`
    |
    = note: expected mutable reference `&mut R`
               found mutable reference `&mut TakeSeek<&mut R>`
note: function defined here
   --> /home/nofitserov/.cargo/registry/src/index.crates.io-6f17d22bba15001f/binrw-0.13.1/src/helpers.rs:213:8
    |
213 | pub fn until_eof<Reader, T, Arg, Ret>(
    |        ^^^^^^^^^

It seems that currently parse_function_args_type_hint unconditionally asserts/requires that the first argument to the parse function is of type &mut R, regardless of map_stream presence.

csnover commented 7 months ago

Thank you for your report! This issue is fixed in 0.13.3.