#[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 backend. The same
attribute is shared with Decode — encoding and decoding of the same type must use the
same backend, so there is no need to distinguish them:
#[codec(prost)]— delegates toprost::Message::encode_to_vec. The target type must also implementprost::Message.#[codec(zerocopy)]— delegates tozerocopy::IntoBytes::as_bytes. The target type must also implementzerocopy::IntoBytes.#[codec(rkyv)]— delegates torkyv::to_bytes. The target type must also implementrkyv::Serialize.
A #[index(N)] attribute must also be present and sets the Encode::ID constant
to the given u64 literal. The value in Encode and Decode must match for the
same message type.
§Example
ⓘ
use acktor_derive::Encode;
#[derive(zerocopy::IntoBytes, Encode)]
#[codec(zerocopy)]
#[index(1)]
struct Ping(u64);