2 releases
Uses old Rust 2015
0.5.1 | Feb 23, 2017 |
---|---|
0.5.0 | Jan 23, 2017 |
#35 in #server-sent-events
63 downloads per month
Used in 9 crates
(via wick-http-client)
8KB
95 lines
uhttp_sse -- HTTP Server-Sent Events protocol
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;