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.
- Add a keyword for the new directive in
parser::keywords. - Define the meta-type of the new directive in
parser::attrs. If you need a new meta-type, add it toparser::meta_typesalong with tests. - If the new directive needs a special final type (e.g.
CondEndian), add that to a newparser::typesmodule and export it fromparser::types. New types must ultimately implementparser::TrySet, but can sometimes do so more simply (using trait generic impls) by implementingFromorTryFrominstead. - Add the new directive as a field to the relevant structs in
parser::top_level_attrsandparser::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
codegen::read_options. - Add new integration tests in the
binreadcrate’stestsdirectory. - If the new directive generates new errors (e.g. from validation), add unit
tests to validate those code paths in
parser::tests(inmod.rs) and add identical trybuild tests to thebinreadcrate’stests/uidirectory. (A nightly compiler is required to run the trybuild tests; see the comment inbinread::tests::uifor more detail.)