#events #server-sent-events #sse #http #server-sent

uhttp_sse

Zero-copy, zero-allocation HTTP Server-Sent Events protocol

2 releases

Uses old Rust 2015

0.5.1 Feb 23, 2017
0.5.0 Jan 23, 2017

#35 in #server-sent-events

Download history 42/week @ 2024-07-21 34/week @ 2024-07-28 24/week @ 2024-08-04 30/week @ 2024-08-11 21/week @ 2024-08-18 28/week @ 2024-08-25 21/week @ 2024-09-01 24/week @ 2024-09-08 22/week @ 2024-09-15 31/week @ 2024-09-22 50/week @ 2024-09-29 7/week @ 2024-10-06 9/week @ 2024-10-13 17/week @ 2024-10-20 19/week @ 2024-10-27 18/week @ 2024-11-03

63 downloads per month
Used in 9 crates (via wick-http-client)

MIT license

8KB
95 lines

uhttp_sse -- HTTP Server-Sent Events protocol

Documentation

This crate provides a zero-copy, zero-allocation implementation of the Server-Sent Events (SSE) protocol for streaming events from an HTTP server.

The events can be written directly to a TcpStream or any other object that implements Write.

Example

use uhttp_sse::SseMessage;
use std::io::Write;

let mut buf = [0; 31];

{
    let mut sse = SseMessage::new(&mut buf[..]);
    write!(sse.event().unwrap(), "ping").unwrap();
    write!(sse.data().unwrap(), "abc").unwrap();
    write!(sse.data().unwrap(), "{}", 1337).unwrap();
}

// This would result in the "ping" event listener being triggered with the data
// payload "abc1337".
assert_eq!(&buf[..], b"event:ping\ndata:abc\ndata:1337\n\n");

Usage

This crate can be used through cargo by adding it as a dependency in Cargo.toml:

[dependencies]
uhttp_sse = "0.5.1"

and importing it in the crate root:

extern crate uhttp_sse;

No runtime deps