[−][src]Struct warp::filters::sse::Sse
Extracted by the sse
filter, and used to reply with stream of events.
Methods
impl Sse
[src]
pub fn reply<S>(self, event_stream: S) -> impl Reply where
S: Stream + Send + 'static,
S::Item: ServerSentEvent,
S::Error: StdError + Send + Sync + 'static,
[src]
S: Stream + Send + 'static,
S::Item: ServerSentEvent,
S::Error: StdError + Send + Sync + 'static,
Server-sent events reply
This function converts stream of server events into reply.
use std::time::Duration; use futures::stream::iter_ok; use warp::{Filter, sse::ServerSentEvent}; #[derive(Serialize)] struct Msg { from: u32, text: String, } let app = warp::path("sse").and(warp::sse()).map(|sse: warp::sse::Sse| { let events = iter_ok::<_, ::std::io::Error>(vec![ // Unnamed event with data only warp::sse::data("payload").boxed(), // Named event with ID and retry timeout ( warp::sse::data("other message\nwith next line"), warp::sse::event("chat"), warp::sse::id(1), warp::sse::retry(Duration::from_millis(15000)) ).boxed(), // Event with JSON data ( warp::sse::id(2), warp::sse::json(Msg { from: 2, text: "hello".into(), }), ).boxed(), ]); sse.reply(events) }); let res = warp::test::request() .method("GET") .header("Connection", "Keep-Alive") .path("/sse") .reply(&app) .into_body(); assert_eq!( res, r#"data:payload event:chat data:other message data:with next line id:1 retry:15000 data:{"from":2,"text":"hello"} id:2 "# );
Trait Implementations
Auto Trait Implementations
impl Send for Sse
impl Unpin for Sse
impl Sync for Sse
impl UnwindSafe for Sse
impl RefUnwindSafe for Sse
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self