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

#1086 in Procedural macros

Download history 21662/week @ 2024-07-12 26041/week @ 2024-07-19 23699/week @ 2024-07-26 25622/week @ 2024-08-02 22946/week @ 2024-08-09 24522/week @ 2024-08-16 20787/week @ 2024-08-23 21446/week @ 2024-08-30 22167/week @ 2024-09-06 18349/week @ 2024-09-13 23140/week @ 2024-09-20 18359/week @ 2024-09-27 19008/week @ 2024-10-04 18807/week @ 2024-10-11 21286/week @ 2024-10-18 18998/week @ 2024-10-25

81,405 downloads per month
Used in 143 crates (3 directly)

MIT license

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.

  1. Add a keyword for the new directive in binrw::parser::keywords.
  2. Define the meta-type of the new directive in binrw::parser::attrs. If you need a new meta-type, add it to meta_types along with tests.
  3. If the new directive needs a special final type (e.g. CondEndian), add that to a new binrw::parser::types module and export it from binrw::parser::types. New types must ultimately implement binrw::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 binrw::parser::top_level_attrs and binrw::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 binrw::codegen::read_options and binrw::codegen::write_options.
  7. Add new integration tests in the binrw 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 binrw::parser::tests (in mod.rs) and add identical trybuild tests to the binrw crate’s tests/ui directory. (A nightly compiler is required to run the trybuild tests; see the comment in binrw::tests::ui for more detail.)

Dependencies

~1.5MB
~38K SLoC