Skip to main content

ToProtoType

Derive Macro ToProtoType 

Source
#[derive(ToProtoType)]
{
    // Attributes available to this derive:
    #[proto]
}
Expand description

Derives a ToProtoType implementation for a struct with named fields.

Each field is mapped to a ProtoField entry (from typeway_grpc). Field tags can be specified explicitly with #[proto(tag = N)]; fields without an explicit tag are auto-numbered based on their 1-indexed position.

Option<T> fields produce optional proto fields. Vec<T> fields produce repeated proto fields (except Vec<u8>, which maps to bytes).

§Example

#[derive(ToProtoType)]
struct User {
    #[proto(tag = 1)]
    id: u32,
    #[proto(tag = 2)]
    name: String,
    #[proto(tag = 3)]
    bio: Option<String>,
}