macro_rules! decode {
($decoder:ident, $msg:ident . $field:ident) => { ... };
($decoder:ident, $field:ident) => { ... };
}Expand description
Decodes a required optional field from a protobuf message using the message’s decoder.
Uses stringify! to automatically derive the field name for error reporting, avoiding
the duplication between a string literal and the field access.
Has two forms:
decode!(decoder, msg.field)— expands todecoder.decode_field("field", msg.field). Use when accessing a field directly on the message value.decode!(decoder, field)— expands todecoder.decode_field("field", field). Use after destructuring the message, when the field is a bare identifier.
§Usage
ⓘ
let decoder = value.decoder();
// With a field access:
let sender = decode!(decoder, value.sender)?;
// With a bare identifier (after destructuring):
let Proto { sender, .. } = value;
let sender = decode!(decoder, sender)?;
// Without `?` to return the Result directly:
decode!(decoder, value.id)