binrw
binrw copied to clipboard
Add support for reference arguments
Todo:
- [x] Document end-user ability to use reference types
- [x] Document limitations regarding manual lifetime specification (eg to use
'_)
- [x] Document limitations regarding manual lifetime specification (eg to use
- [x] Better document how manual
BinReadimplementations now require slight adjustments- [x] Most notably special care should be put towards how this interacts with generics
- [ ] Fix issues regarding
Punctuated's use ofVecArgsbreaking doctests - [ ] Migration guide
- [x] Testing regarding how named arguments interact with reference types
- [ ] Add support for reference types for BinWrite too
Example
#[derive(BinRead, Debug, PartialEq)]
#[br(import(x: &'_ u32, y: &'_ str))]
struct ImportRefs {
#[br(calc(*x))]
a: u32,
#[br(calc(y.to_owned()))]
b: String,
}
Also Adds
-
arg_type!()- a macro which takes a type and turns it into a type that can be suitable for use asBinRead::Args. For example code that previously didtype Args = u32;would now dotype Args = arg_type!(u32);. It also allows for the default lifetime ('_) to be used, so nowtype Args = arg_type!(&'_ u32);works. -
args_of!()- a macro that when given a type expands into the associated type representing the arguments of that type. So code that previously usedT::Argswould now useargs_of!(T)and code that previously used<T as BinRead>::Argswould now useargs_of!(T as BinRead)
Closes #97
Codecov Report
Merging #95 (e5c1080) into master (446f8ff) will increase coverage by
0.13%. The diff coverage is81.08%.
@@ Coverage Diff @@
## master #95 +/- ##
==========================================
+ Coverage 67.59% 67.72% +0.13%
==========================================
Files 63 64 +1
Lines 3148 3170 +22
==========================================
+ Hits 2128 2147 +19
- Misses 1020 1023 +3
| Impacted Files | Coverage Δ | |
|---|---|---|
| binrw/src/helpers.rs | 0.00% <ø> (ø) |
|
| binrw/src/pos_value.rs | 94.44% <ø> (ø) |
|
| binrw/src/private.rs | 60.00% <ø> (ø) |
|
| binrw/src/punctuated.rs | 82.60% <ø> (ø) |
|
| binrw_derive/src/codegen/mod.rs | 80.00% <ø> (ø) |
|
| binrw_derive/src/codegen/read_options/struct.rs | 71.16% <0.00%> (ø) |
|
| binrw_derive/src/lib.rs | 86.88% <ø> (ø) |
|
| binrw/src/binread/mod.rs | 76.92% <66.66%> (-2.25%) |
:arrow_down: |
| binrw_derive/src/args_type.rs | 72.72% <72.72%> (ø) |
|
| binrw/src/binread/impls.rs | 81.63% <100.00%> (ø) |
|
| ... and 5 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 446f8ff...e5c1080. Read the comment docs.