23 unstable releases
0.14.1 | Oct 13, 2024 |
---|---|
0.14.0 | Jun 7, 2024 |
0.13.3 | Nov 29, 2023 |
0.11.2 | May 15, 2023 |
0.2.0 | Mar 24, 2021 |
#1463 in Procedural macros
76,677 downloads per month
Used in 150 crates
(3 directly)
240KB
6.5K
SLoC
binrw_derive
Quick start for adding a new directive to binrw
In all cases, look to existing directives to follow established code and test conventions.
- Add a keyword for the new directive in
binrw::parser::keywords
. - Define the meta-type of the new directive in
binrw::parser::attrs
. If you need a new meta-type, add it tometa_types
along with tests. - If the new directive needs a special final type (e.g.
CondEndian
), add that to a newbinrw::parser::types
module and export it frombinrw::parser::types
. New types must ultimately implementbinrw::parser::TrySet
, but can sometimes do so more simply (using trait generic impls) by implementingFrom
orTryFrom
instead. - Add the new directive as a field to the relevant structs in
binrw::parser::top_level_attrs
andbinrw::parser::field_level_attrs
. - If the new directive combines with other directives in ways that may be
invalid, and the relationship cannot be expressed using an enum type
(e.g.
ReadMode
), add validation in eitherFromInput::push_field
(if the validation can occur immediately after the field is constructed) orFromInput::validate
(if it can only be validated after the entire struct has been parsed). - Use the new fields to emit code in the appropriate places in
binrw::codegen::read_options
andbinrw::codegen::write_options
. - Add new integration tests in the
binrw
crate’stests
directory. - If the new directive generates new errors (e.g. from validation), add unit
tests to validate those code paths in
binrw::parser::tests
(inmod.rs
) and add identical trybuild tests to thebinrw
crate’stests/ui
directory. (A nightly compiler is required to run the trybuild tests; see the comment inbinrw::tests::ui
for more detail.)
Dependencies
~1.5MB
~39K SLoC