#[derive(Encode)]
{
// Attributes available to this derive:
#[codec]
}
Available on crate feature
ipc only.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(serde_json)]— delegates toserde_json::to_vec. The target type (or the bridge type) must implementserde::Serialize.#[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.
§Example
ⓘ
use acktor_derive::Encode;
#[derive(zerocopy::IntoBytes, Encode)]
#[codec(zerocopy)]
struct Ping(u64);