data-stream-derive 0.1.0

Derive macros for data-stream
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 20.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 320.42 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • porky11

Data Stream Derive

data-stream-derive provides procedural macros for (data-stream)[https://gitlab.com/porky11/data-stream]:

  • #[derive(ToStream)]
  • #[derive(FromStream)]

It generates stream serialization and deserialization code for structs and enums.

Quick example

use data_stream::{FromStream, ToStream};

#[derive(ToStream, FromStream)]
struct SaveData {
    id: u32,
    name: String,
}

Supported attributes

Container attributes

#[stream(bounds = "...")]

use data_stream::{FromStream, ToStream};
use data_stream::collections::SizeSettings;

#[derive(ToStream, FromStream)]
#[stream(bounds = "SizeSettings")]
struct Wrapper<T> {
    value: T,
}

Field attributes

#[field(ignore)]
Ignored fields are not serialized and are filled with Default::default() on deserialize.

#[field(order = N)]
Controls read/write order of fields.

use data_stream::{FromStream, ToStream};

#[derive(ToStream, FromStream)]
struct Ordered {
    #[field(order = 1)]
    b: u32,
    #[field(order = 0)]
    a: u32,
    #[field(ignore)]
    cache: u32,
}

Variant attributes

#[variant(index = N)]
Sets a fixed enum discriminant value.

use data_stream::{FromStream, ToStream};

#[derive(ToStream, FromStream)]
enum Message {
    #[variant(index = 1)]
    Ping,
    #[variant(index = 2)]
    Pong(u32),
}