#[derive(TypewayCodec)]
{
// Attributes available to this derive:
#[proto]
}
Expand description
Derive TypewayEncode and TypewayDecode for a struct.
Generates specialized encode/decode functions with no runtime dispatch. Each field is encoded/decoded directly based on its Rust type and proto tag number.
§Attributes
#[proto(tag = N)]— Set the protobuf field tag number (default: 1-indexed position)
§Supported field types
| Rust type | Proto type | Wire type |
|---|---|---|
u32 | uint32 | varint (0) |
u64 | uint64 | varint (0) |
i32 | int32 | varint (0) |
i64 | int64 | varint (0) |
bool | bool | varint (0) |
f32 | float | 32-bit (5) |
f64 | double | 64-bit (1) |
String | string | len-delimited (2) |
Vec<u8> | bytes | len-delimited (2) |
Vec<T> | repeated T | (varies) |
Option<T> | optional T | (varies) |
§Example
ⓘ
#[derive(TypewayCodec)]
struct User {
#[proto(tag = 1)]
id: u32,
#[proto(tag = 2)]
name: String,
#[proto(tag = 3)]
active: bool,
}