#zero-copy #serialization #bincode #bit-packing

macro no-std bincode_derive-next

Procedural macros for bincode-next: high-performance derive macros for Encode, Decode, ZeroCopy, and more

10 releases (5 stable)

Uses new Rust 2024

new 3.0.0-rc.5 Mar 7, 2026
3.0.0-rc.4 Mar 3, 2026
3.0.0-rc.2 Feb 25, 2026
2.1.0 Feb 17, 2026
2.0.4 Dec 21, 2025

#15 in #bit-packing

Download history 11/week @ 2025-12-13 262/week @ 2025-12-20 204/week @ 2025-12-27 263/week @ 2026-01-03 208/week @ 2026-01-10 209/week @ 2026-01-17 394/week @ 2026-01-24 974/week @ 2026-01-31 1387/week @ 2026-02-07 3269/week @ 2026-02-14 6755/week @ 2026-02-21 7799/week @ 2026-02-28

19,345 downloads per month
Used in bincode-next

MIT or Apache-2.0

155KB
3K SLoC

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 currently
  • Visibility, not being used currently
  • DataType either Struct or Enum, with the name of the data type being parsed
  • Generics the generics part of the type, e.g. struct Foo<'a>
  • GenericConstraints the "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:

  • StreamBuilder is a thin but friendly wrapper around TokenStream
  • Generator is the base type of the code generator. This has helper methods to generate implementations:
    • ImplFor is a helper struct for a single impl A for B construction. In this functions can be defined:
      • GenerateFnBody is a helper struct for a single function in the above impl. This is created with a callback to FnBuilder which helps set some properties. GenerateFnBody has a stream() function which returns StreamBuilder for 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.

Dependencies

~200KB