Bincode-derive
The derive crate for bincode. Implements bincode::Encode and bincode::Decode.
This crate is roughly split into 2 parts:
Parsing
Most of parsing is done in the src/parse/ folder. This will generate the following types:
Attributes, not being used currentlyVisibility, not being used currentlyDataTypeeitherStructorEnum, with the name of the data type being parsedGenericsthe generics part of the type, e.g.struct Foo<'a>GenericConstraintsthe "where" part of the type
Generate
Generating the code implementation is done in either src/derive_enum.rs and src/derive_struct.rs.
This is supported by the structs in src/generate. The most notable points of this module are:
StreamBuilderis a thin but friendly wrapper aroundTokenStreamGeneratoris the base type of the code generator. This has helper methods to generate implementations:ImplForis a helper struct for a singleimpl A for Bconstruction. In this functions can be defined:GenerateFnBodyis a helper struct for a single function in the aboveimpl. This is created with a callback toFnBuilderwhich helps set some properties.GenerateFnBodyhas astream()function which returnsStreamBuilderfor the function.
For additional derive testing, see the test cases in ../tests
For testing purposes, all generated code is outputted to the current target/generated/bincode folder, under file name <struct/enum name>_Encode.rs and <struct/enum name>_Decode.rs. This can help with debugging.