#[derive(Encode)]
{
// Attributes available to this derive:
#[codec]
#[index]
}
Expand description
Derive the Encode trait for a message.
A #[codec(..)] attribute must be present to select the serialization method and the same
attribute is shared with Decode. Encoding and decoding of the same message type must use
the same method. The attribute also supports an optional bridge type that serves as an
intermediary for encoding and decoding, which is useful when the message type itself cannot
directly implement the required traits. Currently there are three supported codec methods:
#[codec(prost)]— delegates toprost::Message::encode_to_vec. The target type (or the bridge type) must implementprost::Message.#[codec(zerocopy)]— delegates tozerocopy::IntoBytes::as_bytes. The target type (or the bridge type) must implementzerocopy::IntoBytes.#[codec(rkyv)]— delegates torkyv::to_bytes. The target type (or the bridge type) must implementrkyv::Serialize.
If a bridge type T is specified, the bridge type must be convertible from the target type
with impl From<&Self> for T.
A #[index(N)] attribute must also be present to set the Encode::ID constant with the given
u64 literal. The index in Encode and Decode must be the same for the same message
type.
§Example
use acktor_derive::Encode;
#[derive(zerocopy::IntoBytes, Encode)]
#[codec(zerocopy)]
#[index(1)]
struct Ping(u64);