basalt-derive 0.2.1

Derive macros for Encode/Decode/EncodedSize traits
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 42.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 409.59 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • basalt-mc/basalt
    4 1 6
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • iverly

basalt-derive

Proc-macro crate for the Basalt Minecraft server. Generates Encode, Decode, and EncodedSize trait implementations for protocol packet structs and inner data types.

Macros

#[packet(id = N)]

Attribute macro for protocol packets. Generates all three trait impls plus a PACKET_ID constant:

#[derive(Debug, Clone, PartialEq)]
#[packet(id = 0x00)]
pub struct StatusRequest;

#[derive(Encode, Decode, EncodedSize)]

Standard derive macros for non-packet types (inline structs, enums, inner data structures):

#[derive(Debug, Encode, Decode, EncodedSize)]
pub struct PlayerPosition {
    pub x: f64,
    pub y: f64,
    pub z: f64,
    pub on_ground: bool,
}

Field attributes

Attribute Effect
#[field(varint)] Encode i32 as VarInt (1-5 bytes)
#[field(varlong)] Encode i64 as VarLong (1-10 bytes)
#[field(optional)] Boolean-prefixed Option<T>
#[field(length = "varint")] VarInt length prefix for Vec<T>
#[field(element = "varint")] Encode each element as VarInt
#[field(rest)] Consume remaining bytes (last field only)

Variant attributes

#[variant(id = N)] on enum variants for discriminator-based dispatch. The discriminant is encoded as a VarInt.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.