Function eventsource::event::parse_event_line
[−]
[src]
pub fn parse_event_line(line: &str, event: &mut Event) -> ParseResult
Parse a single line of an event-stream.
The line may end with a newline.
You will have to call this function multiple times until it returns ParseResult::Dispatch
.
Make sure to clear the event struct for the next line, then.
To handle the Last-Event-ID
header, check the id
field for each finished event.
Examples
let mut event = Event::new(); assert_eq!(parse_event_line("id: 42", &mut event), ParseResult::Next); assert_eq!(parse_event_line("data: foobar", &mut event), ParseResult::Next); assert_eq!(parse_event_line("", &mut event), ParseResult::Dispatch); // The event is finished now. assert_eq!(event.id, Some("42".into())); assert_eq!(event.data, "foobar\n"); // Now clear and continue. event.clear(); // ...