Skip to main content

reply

Macro reply 

Source
macro_rules! reply {
    (status = $status:expr, headers = { $($k:literal : $v:expr),* $(,)? }, $body:expr) => { ... };
    (status = $status:expr, $body:expr) => { ... };
    (stream: $s:expr) => { ... };
    (sse: $s:expr) => { ... };
    () => { ... };
    ($expr:expr) => { ... };
}
Expand description

Creates a Reply (a Result<ReplyData, WebError>) for a success case.

Accepts any Serialize value; failures during JSON conversion become Err(WebError::Internal(...)) (→ 500) rather than panicking. The underlying json function still panics for callers that prefer to surface bugs loudly; if you need that, call it directly.

reply!(my_struct)                          // serialize as JSON
reply!(json!({"status": "ok"}))            // inline JSON literal
reply!()                                   // 204 No Content
reply!(stream: byte_stream)                // streaming body
reply!(sse: event_stream)                  // Server-Sent Events
reply!(status = StatusCode::CREATED, value)
reply!(
    status = StatusCode::CREATED,
    headers = { "Location": "/users/123" },
    value
)