jam1garner / binrw

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

brw(import) seems to always produce an error in expansion #123

Closed Gorialis closed 2 years ago

Gorialis commented 2 years ago

The following:

use binrw::*;

#[derive(Clone)]
#[binrw]
#[brw(import { threshold: u8 })]
struct Blah {}

produces this error: image

This error appears to be caused by the import line, and goes away if you adjust it to either #[bw(import { threshold: u8 })] or #[br(import { threshold: u8 })]. This doesn't work for my use case, since both the reading and writing require state that isn't determinable statically.

Note that the same thing occurs if you include both bw and br instead of one brw, and it doesn't go away if you use a different struct or arg names between br and bw. (edit: It also doesn't go away if you don't derive Clone)

This is with binrw 0.8.4 (checksum a13d2fa8772b88ee64a0d84602c636ad2bae9c176873f6c440e2b0a1df4c8c43), rustc 1.60.0 with either the stable or nightly toolchain.

jam1garner commented 2 years ago

yep, looks like a clear cut copy/paste error (I forgot to make the name of the Write builder different). My bad! thank you for the report. I'll try to get a fix out soon

jam1garner commented 2 years ago

actually wait I think this is already fixed on master, if you need a prerelease of 0.9.0 pushed to crates.io feel free to @ me.

Gorialis commented 2 years ago

This does indeed seem to be fixed on master. Thanks!