Proto Builder Trait

This crate simplifies the work to add extra attributes for prost-build/tonic-build generated code.

Usage

Add this to your Cargo.toml:

```toml [dependencies] sqlx = "..." derive_builder = "..." serde = "..."

[build-dependencies] proto-builder-trait = "0.1" ```

In your build.rs:

```rust use protobuildertrait::prost::BuilderAttributes; use prost_build::Config;

fn main() { Config::default() .outdir(path.path()) .withserde(&["todo.Todo", "todo.TodoStatus"], true, true) .withderivebuilder(&["todo.Todo"]) .withsqlxtype(&["todo.TodoStatus"]) .withfieldattributes( &["todo.Todo.createdat", "todo.Todo.updatedat"], &["#[derive(Copy)]"], ) .compile_protos(&["fixtures/protos/todo.proto"], &["fixtures/protos"]) .unwrap(); } ```

This will generate the following code:

```rust

[derive(serde::Serialize, serde::Deserialize)]

[derive(derive_builder::Builder)]

[builder(setter(into, strip_option), default)]

[derive(Clone, PartialEq, ::prost::Message)]

pub struct Todo { #[prost(string, tag="1")] pub id: ::prost::alloc::string::String, #[prost(string, tag="2")] pub title: ::prost::alloc::string::String, #[prost(string, tag="3")] pub description: ::prost::alloc::string::String, #[prost(enumeration="TodoStatus", tag="4")] pub status: i32, #[prost(message, optional, tag="5")] #[derive(Copy)] pub createdat: ::core::option::Option<::prosttypes::Timestamp>, #[prost(message, optional, tag="6")] #[derive(Copy)] pub updatedat: ::core::option::Option<::prosttypes::Timestamp>, }

[derive(Clone, PartialEq, ::prost::Message)]

pub struct GetTodosRequest { #[prost(string, repeated, tag="1")] pub id: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, }

[derive(Clone, PartialEq, ::prost::Message)]

pub struct CreateTodoRequest { #[prost(string, tag="1")] pub title: ::prost::alloc::string::String, #[prost(string, tag="2")] pub description: ::prost::alloc::string::String, }

[derive(Clone, PartialEq, ::prost::Message)]

pub struct DeleteTodoRequest { #[prost(string, tag="1")] pub id: ::prost::alloc::string::String, }

[derive(Clone, PartialEq, ::prost::Message)]

pub struct DeleteTodoResponse { }

[derive(serde::Serialize, serde::Deserialize)]

[derive(sqlx::Type)]

[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]

[repr(i32)]

pub enum TodoStatus { Doing = 0, Done = 1, } impl TodoStatus { /// String value of the enum field names used in the ProtoBuf definition. /// /// The values are not transformed in any way and thus are considered stable /// (if the ProtoBuf definition does not change) and safe for programmatic use. pub fn asstrname(&self) -> &'static str { match self { TodoStatus::Doing => "TODOSTATUSDOING", TodoStatus::Done => "TODOSTATUSDONE", } } } ```