-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
br(count = ...)
conflicts with br(args(...))
#112
Comments
The thing that jumps out at me, is that you're using In general, Does this help? |
Thanks, this does indeed work: use binrw::{binrw, BinRead};
#[binrw]
#[derive(Debug)]
#[brw(little)]
struct Data {
version: u16,
#[br(temp)]
#[bw(calc = items.len().try_into().unwrap())]
num_items: u32,
#[br(args{ count: num_items.try_into().unwrap(), inner: (version,) })]
items: Vec<Item>,
}
#[binrw]
#[derive(Debug)]
#[brw(little)]
#[br(import(version: u16))]
struct Item {
field1: u32,
#[br(if(version >= 5, 0))]
field2: u64,
}
fn main() {
let path = std::env::args().nth(1).expect("no path given");
let mut reader = std::fs::File::open(&path).expect("failed to open file");
let data = Data::read(&mut reader).expect("failed to parse file");
println!("{:#04x?}", data);
} But it feels like I'm hacking around some implementation detail of the library, so it would be nice if this would receive a proper fix. |
Btw, I just saw that this workaround actually documented in 38f731b. |
Links to the documentation added in 38f731b, which was only referenced by the `count` documentation, but not `args`. Related issue: jam1garner#112
This commit provides an explicit message when someone combines count + args in a way which is not valid, which was the primary issue, and then also improves the diagnostic output for cases where someone passes the wrong type of arguments to point to the invalid args expression and the type of the field. Notably, this does not resolve most issues with named arguments as those are typically errors caused by calling non-existent builders and builder functions, which requires a different strategy. Closes jam1garner#112.
There is now an explicit error message explaining the problem and what to do instead. Thanks for your report! |
Apparently it's not possible to to pass a arguments to a
Vec
ofBinRead
objects.Here's an example:
This results in the following error:
The text was updated successfully, but these errors were encountered: