Skip to main content

Crate qbice_serialize_derive

Crate qbice_serialize_derive 

Source
Expand description

Derive macros for the Encode and Decode traits.

This crate provides derive macros for automatically implementing the Encode and Decode traits.

§Supported Types

The derive macros support:

  • Structs with named fields
  • Tuple structs
  • Unit structs
  • Enums with any combination of unit, tuple, and struct variants

§Examples

§Struct with Named Fields

ⓘ
#[derive(Encode, Decode)]
struct Point {
    x: i32,
    y: i32,
}

§Tuple Struct

ⓘ
#[derive(Encode, Decode)]
struct Id(u64);

§Unit Struct

ⓘ
#[derive(Encode, Decode)]
struct Marker;

§Enum

ⓘ
#[derive(Encode, Decode)]
enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
}

§Field Attributes

§#[serialize(skip)]

Skip a field during serialization and use Default::default() during deserialization.

ⓘ
#[derive(Encode, Decode)]
struct Config {
    name: String,
    #[serialize(skip)]
    cache: Vec<u8>, // Uses Default::default() when decoding
}

Derive Macros§

Decode
Derive macro for Decode.
Encode
Derive macro for Encode.