pack-io-derive 0.8.0

Procedural macros for `pack-io`. Provides #[derive(Serialize, Deserialize, DeserializeView)].
Documentation

Installation

Don't depend on pack-io-derive directly. Depend on pack-io with the derive feature:

[dependencies]
pack-io = { version = "0.4", features = ["derive"] }

What the macros do

Three derives, all working on structs (named-field, tuple, unit) and enums (any variant shape), generic over type parameters:

use pack_io::{Serialize, Deserialize, DeserializeView};

#[derive(Serialize, Deserialize)]
struct Account {
    id: u64,
    handle: String,
    active: bool,
}

#[derive(Serialize, Deserialize)]
enum Event {
    Heartbeat,
    Login { user: u64, ip: String },
    Error(u32, String),
}

#[derive(DeserializeView)]
struct AccountView<'a> {
    id: u64,
    handle: &'a str,   // borrows directly from the input buffer
    active: bool,
}
Derive Implements Notes
Serialize pack_io::Serialize Generic over the pack_io::Encode behaviour trait.
Deserialize pack_io::Deserialize Generic over the pack_io::Decode behaviour trait. Owning decode.
DeserializeView pack_io::DeserializeView<'a> Zero-copy. Struct must have exactly one lifetime parameter.

Generated code is generic over Encode / Decode, so the same impl drives both the in-memory codec and the streaming IoEncoder<W> / IoDecoder<R> in the parent crate.

Field order in the source code is the encoded byte order. For enums, a varint(variant_index) prefix is emitted first, in source-declaration order starting at 0. Append new variants to the end of an enum declaration to keep the wire shape backward-compatible — inserting in the middle shifts every later variant's index.

See the full wire-format specification and the API reference in the parent repository.

Compatibility

  • MSRV: Rust 1.85 (2024 edition).
  • Version pinning: pack-io depends on pack-io-derive with an exact =X.Y.Z constraint so mismatched derive output cannot leak across pack-io revisions.