jam1garner / jam1garner/binwrite
derive macro silently fails when ran on a tuple struct
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 18
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Apologies, this isn't exactly a minimal test, just how I discovered it.
```rust
use binread::{BinRead, NullString};
use binwrite::BinWrite;
// this *compiles* but does not behave as exepected.
#[derive(BinRead, BinWrite, Clone, PartialEq, Default)]
pub struct BadNullString(
#[binwrite(cstr, preprocessor(NullString::to_string))]
NullString
);
#[test]
fn test_bad() {
let test = BadNullString(NullString(Vec::from(&b"Test!"[..])));
let expected = Vec::from(&b"Test!\0"[..]);
let mut writer = std::io::Cursor::new(Vec::new());
test.write(&mut writer).unwrap();
let res = writer.into_inner();
assert_eq!(res, expected); // fails, res has no bytes in it
}
// this works correctly
#[derive(BinRead, BinWrite, Clone, PartialEq, Default)]
pub struct GoodNullString {
#[binwrite(cstr, preprocessor(NullString::to_string))]
inner: NullString
}
#[test]
fn test_good() {
let test = GoodNullString { inner: NullString(Vec::from(&b"Test!"[..])) };
let expected = Vec::from(&b"Test!\0"[..]);
let mut writer = std::io::Cursor::new(Vec::new());
test.write(&mut writer).unwrap();
let res = writer.into_inner();
assert_eq!(res, expected); // passes
}
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided tuple-struct and named-struct tests, then locate the BinWrite derive macro entry point and compare how each struct shape is expanded. Done means the tuple-struct case writes the expected Test!\0 bytes while the named-struct case continues to pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100