Skip to main content

Encode

Derive Macro Encode 

Source
#[derive(Encode)]
{
    // Attributes available to this derive:
    #[msgpack]
}
Available on crate feature derive only.
Expand description

Derive the Encode trait for a struct.

§Supported types

  • Named-field structs — encoded as a MessagePack map by default
  • Tuple structs — encoded as a MessagePack array
  • Unit structs — encoded as MessagePack nil

§Container attributes

  • #[msgpack(map)] — encode as a MessagePack map (default for named-field structs)
  • #[msgpack(array)] — encode as a MessagePack array

§Field attributes

  • #[msgpack(key = N)] — required for all fields in array mode
  • #[msgpack(bytes)] — encode the field as MessagePack binary
  • #[msgpack(encode_with = "path::to::fn")] — custom encode function