Skip to main content

EventType

Derive Macro EventType 

Source
#[derive(EventType)]
{
    // Attributes available to this derive:
    #[sioc]
}
Expand description

Derives the EventType trait, providing the event name constant and ack/binary policy associated types.

Serialization and deserialization are not included; derive SerializePayload for emit and DeserializePayload for recv as needed.

§Attributes

  • #[sioc(event(name = "str"))]: override the wire name. Without it the struct name is converted to snake_case.
  • #[sioc(event(ack = Type))]: set type Ack = HasAck<Type> (default: NoAck).
  • #[sioc(event(binary))]: set type Binary = HasBinary (default: NoBinary).

§Example

// ignore: sioc-macros cannot dev-depend on sioc (circular); see sioc crate for runnable examples.
use sioc::prelude::*;

// Emit-only; name defaults to "server_ping".
#[derive(EventType, SerializePayload)]
struct ServerPing;

// Recv-only with an explicit name.
#[derive(EventType, DeserializePayload)]
#[sioc(event(name = "user_joined"))]
struct UserJoined {
    id: u64,
    name: String,
}