Derive macros for Sioc: generate typed Socket.IO event and acknowledgement types.
The four core traits are intentionally separate so you only derive what each use-site needs:
| Trait | Derive | Needed for |
|---|---|---|
[EventType] |
#[derive(EventType)] |
event name constant + ack/binary policy |
[AckType] |
#[derive(AckType)] |
ack binary policy |
[SerializePayload] |
#[derive(SerializePayload)] |
emitting (outbound) |
[DeserializePayload] |
#[derive(DeserializePayload)] |
receiving (inbound) |
#[derive(EventRouter)] is a convenience that generates TryFrom<DynEvent> for
a dispatcher enum whose variants each wrap an Event<E>.
Struct-level attributes (#[sioc(...)])
| Attribute | Applies to | Effect |
|---|---|---|
event(name = "str") |
EventType |
Override the event name (default: snake_case of struct name). |
event(ack = Type) |
EventType |
Set ack policy to HasAck<Type>; default is NoAck. |
event(binary) |
EventType |
Set binary policy to HasBinary; default is NoBinary. |
ack(binary) |
AckType |
Set binary policy to HasBinary; default is NoBinary. |
strict |
DeserializePayload |
Reject payloads with more elements than fields (error on trailing data). |
Field-level attributes (#[sioc(...)])
| Attribute | Applies to | Effect |
|---|---|---|
flatten |
SerializePayload, DeserializePayload |
Serialize each element of this collection field as a separate array element; deserialize all remaining elements into it. Place last. |
Example
// ignore: sioc-macros cannot dev-depend on sioc (circular); see sioc crate for runnable examples.
use *;
// Emit-only: only SerializePayload is required.
;
// Recv-only: only DeserializePayload is required.
;
// Bidirectional with an explicit name.
// Ack receive-only.