#protobuf #derive #protocols

macro proto_convert_derive

Automatically derive Protobuf and Rust conversions

16 releases

0.1.15 Mar 16, 2025
0.1.14 Mar 15, 2025

#371 in Procedural macros

Download history 801/week @ 2025-03-05 394/week @ 2025-03-12 46/week @ 2025-03-19

1,241 downloads per month

Apache-2.0

31KB
477 lines

proto_convert_derive

Automatically derive conversions between Protobuf-compiled prost types and your native Rust types.

Overview

proto_convert_derive is a procedural macro for bidirectional conversions between Protobuf-generated types (prost) and Rust structs. This reduces boilerplate and handles proto3's lack of required fields (which result in Option and lots .expect or if let Some in your code. This macro simply .expects types.

Key Features

  • Automatically implements From<Proto> for Rust types and vice versa.
  • Supports collections like Vec<Proto>
  • Direct mapping for primitive types.
  • Unwraps optional fields with .expect.
  • Supports newtype wrappers.
  • Customizable Protobuf module (default is proto via #[proto(module = "your_module")]).
  • Ignore individual fields #[proto(ignore)]

Usage

Head to the examples.

Dependencies

~200–630KB
~15K SLoC