packetwire-derive
Procedural attribute macros for
packetwire, a bounded binary packet codec with
stream and datagram framing.
Most applications should depend only on packetwire. It re-exports these
macros together with the traits and framing types used by the generated code:
[]
= "0.1"
Packet structs
#[packet] assigns a stable 16-bit packet ID and implements BinaryEncode,
BinaryDecode, and Packet. Named, tuple, unit, and generic structs are
supported. Fields are encoded and decoded in declaration order.
Both attribute forms are equivalent:
use packet;
;
Every field type must implement both BinaryEncode and BinaryDecode. The
macro adds those bounds to generated implementations for generic structs.
Place #[packet] before ordinary derive attributes so those attributes remain
attached to the emitted struct:
use packet;
;
Packet sets
#[packet_set] turns a non-empty enum of single-field tuple variants into a
packet dispatcher. Each variant field must be a type implementing Packet,
normally through #[packet].
The macro implements PacketSet, PacketEncode, and From<PacketType> for
the enum. Duplicate packet IDs are rejected at compile time.
use ;
Packet-set enums cannot be generic, cannot contain discriminants, and must use exactly one unnamed packet field per variant.
Direct dependency
This crate is primarily an implementation detail of packetwire. Depending on
it directly does not provide the traits referenced by generated code, so the
main packetwire crate must still be available. Renamed packetwire
dependencies are detected automatically.
License
MIT