12 stable releases

2.1.0 Aug 25, 2021
2.0.0 Mar 18, 2021
1.4.3 Jan 12, 2021
1.4.2 Nov 29, 2020
1.0.2 Jun 26, 2020

#181 in #field

Download history 11507/week @ 2023-11-21 16656/week @ 2023-11-28 18131/week @ 2023-12-05 16264/week @ 2023-12-12 9086/week @ 2023-12-19 4662/week @ 2023-12-26 8340/week @ 2024-01-02 10707/week @ 2024-01-09 11914/week @ 2024-01-16 12428/week @ 2024-01-23 14112/week @ 2024-01-30 19896/week @ 2024-02-06 19882/week @ 2024-02-13 15922/week @ 2024-02-20 13664/week @ 2024-02-27 13157/week @ 2024-03-05

66,322 downloads per month
Used in 209 crates (via binread)

MIT license

98KB
3K SLoC

binread_derive

Quick start for adding a new directive to BinRead

In all cases, look to existing directives to follow established code and test conventions.

  1. Add a keyword for the new directive in parser::keywords.
  2. Define the meta-type of the new directive in parser::attrs. If you need a new meta-type, add it to parser::meta_types along with tests.
  3. If the new directive needs a special final type (e.g. CondEndian), add that to a new parser::types module and export it from parser::types. New types must ultimately implement parser::TrySet, but can sometimes do so more simply (using trait generic impls) by implementing From or TryFrom instead.
  4. Add the new directive as a field to the relevant structs in parser::top_level_attrs and parser::field_level_attrs.
  5. 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 either FromInput::push_field (if the validation can occur immediately after the field is constructed) or FromInput::validate (if it can only be validated after the entire struct has been parsed).
  6. Use the new fields to emit code in the appropriate places in codegen::read_options.
  7. Add new integration tests in the binread crate’s tests directory.
  8. If the new directive generates new errors (e.g. from validation), add unit tests to validate those code paths in parser::tests (in mod.rs) and add identical trybuild tests to the binread crate’s tests/ui directory. (A nightly compiler is required to run the trybuild tests; see the comment in binread::tests::ui for more detail.)

Dependencies

~1.5MB
~33K SLoC