#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

#26 in #server-sent-events

Download history 52/week @ 2024-04-08 61/week @ 2024-04-15 53/week @ 2024-04-22 31/week @ 2024-04-29 24/week @ 2024-05-06 48/week @ 2024-05-13 28/week @ 2024-05-20 38/week @ 2024-05-27 31/week @ 2024-06-03 26/week @ 2024-06-10 29/week @ 2024-06-17 46/week @ 2024-06-24 19/week @ 2024-07-08 56/week @ 2024-07-15 37/week @ 2024-07-22

120 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