Skip to main content

SseEvent

Derive Macro SseEvent 

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

Derive SseEventMeta for an enum whose variants represent the events of a Server-Sent Event stream.

Pair with upstream serde::Serialize and utoipa::ToSchema derives plus #[serde(tag = "event", content = "data", rename_all = "snake_case")] so the wire format and the OpenAPI schema stay aligned. Each variant’s event name defaults to its snake-case form; override with #[sse(name = "…")].

use doxa::SseEvent;

#[derive(serde::Serialize, utoipa::ToSchema, SseEvent)]
#[serde(tag = "event", content = "data", rename_all = "snake_case")]
enum MigrationEvent {
    Started { pipeline: String },
    Progress { done: u64, total: u64 },
    #[sse(name = "finished")]
    Completed,
    Heartbeat,
}

The derive does not implement Serialize or ToSchema itself — that keeps serde’s renaming rules authoritative and avoids duplicating them in this crate.