Crate durian_proc_macros

Crate durian_proc_macros 

Source
Expand description

Procedural macros for the durian crate

Contains macros for easily annotating structs as Packets and automatically implementing PacketBuilders. The only requirement is the struct must be de/serializable, meaning all nested fields also need to be de/serializable.

#[bincode_packet] will de/serialize your Packet using bincode and applies necessary derive macros automatically for you.

use durian::bincode_packet;

// Automatically implements Packet, and generates a PositionPacketBuilder that implements
// PacketBuilder.  You can also add other macros such as derive macros so long s they don't
// conflict with what #[bincode_packet] adds (See bincode_packet documentation).
#[bincode_packet]
#[derive(Debug)]
struct Position {
    x: i32,
    y: i32
}

// Works for Unit (empty) structs as well
#[bincode_packet]
struct Ack;

You can also use the derive macros (BinPacket and UnitPacket) manually:

use durian::serde::{Deserialize, Serialize};
use durian::{BinPacket, UnitPacket};

#[derive(Serialize, Deserialize, BinPacket)]
#[serde(crate = "durian::serde")]
struct Position { x: i32, y: i32 }

#[derive(UnitPacket)]
struct Ack;

Attribute Macros§

bincode_packet
Macros for easy creation of Packets and PacketBuilders

Derive Macros§

BinPacket
derive macro to automatically implement Packet and PacketBuilder for a struct.
DerefPacketManager
Convenience derive macro that implements [Deref] and [DerefMut] for a struct that contains a manager: PacketManager field.
ErrorOnlyMessage
Implements a new() function for a struct that contains only a message: String field
UnitPacket
Same as BinPacket but for empty or Unit structs