#serde-derive #prost #macro-derive

macro prost-serde-derive

Derive macro for serializing/deserializing structs generated by Prost with Serde

5 releases

0.1.5 Mar 22, 2024
0.1.4 Mar 21, 2024
0.1.2 Mar 30, 2023
0.1.1 Feb 13, 2023
0.1.0 Dec 19, 2022

#994 in Procedural macros

Download history 495/week @ 2024-07-25 246/week @ 2024-08-01 316/week @ 2024-08-08 207/week @ 2024-08-15 536/week @ 2024-08-22 852/week @ 2024-08-29 951/week @ 2024-09-05 496/week @ 2024-09-12 596/week @ 2024-09-19 533/week @ 2024-09-26 433/week @ 2024-10-03 302/week @ 2024-10-10 160/week @ 2024-10-17 215/week @ 2024-10-24 126/week @ 2024-10-31 228/week @ 2024-11-07

801 downloads per month
Used in tucana-internal

Custom license

40KB
940 lines

prost-serde-derive is a procedural macro for serializing/deserializing structs generated by Prost with Serde.

How to use

When using tonic-build, add type attribute to the structs/enums like following:

fn main() {
    tonic_build::configure()
        .type_attribute("some.proto.SomeStruct", "#[derive(prost_serde_derive::Deserialize, prost_serde_derive::Serialize)]")
        // Add following if you have to allow missing non-nullable fields when deserializing (will be filled with the default value)
        .type_attribute("some.proto.SomeStruct", "#[prost_serde_derive(use_default_for_missing_fields)]")
        // Add following if you have to allow deserializing even if there are type errors
        .type_attribute("some.proto.SomeStruct", "#[prost_serde_derive(omit_type_errors)]")
        // Serializing/deserializing Prost enumerations are also available
        .type_attribute("some.proto.SomeEnum", "#[derive(prost_serde_derive::Deserialize, prost_serde_derive::Serialize)]")
        .compile(...);
}

Make sure to include base64 to your dependencies when bytes type is used in your proto.

Dependencies

~2.5MB
~51K SLoC