prost-serde-derive

Crates.ioprost-serde-derive
lib.rsprost-serde-derive
version0.1.5
sourcesrc
created_at2022-12-19 04:20:00.980733
updated_at2024-03-22 06:09:14.046989
descriptionDerive macro for serializing/deserializing structs generated by Prost with Serde
homepagehttps://github.com/segfault87/prost-serde-derive
repositoryhttps://github.com/segfault87/prost-serde-derive
max_upload_size
id740780
size40,269
Park Joon-Kyu (segfault87)

documentation

https://github.com/segfault87/prost-serde-derive/blob/main/README.md

README

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.

Commit count: 32

cargo fmt