1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::util::HeaderValueString;
use std::{fmt, str::FromStr};
/// `Last-Event-ID` header, defined in
/// [WhatWG's SSE spec](https://html.spec.whatwg.org/multipage/server-sent-events.html#the-last-event-id-header)
///
/// The Last-Event-ID` HTTP request header reports an EventSource object's
/// last event ID string to the server when the user agent is to reestablish the connection.
///
/// The spec is a String with the id of the last event, it can be
/// an empty string which acts a sort of "reset".
#[derive(Clone, Debug, PartialEq)]
pub struct LastEventId(HeaderValueString);
derive_header! {
LastEventId(_),
name: LAST_EVENT_ID
}
impl LastEventId {
#[inline]
/// Return the id as a borrowed string.
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl AsRef<str> for LastEventId {
#[inline]
/// Return the id as a borrowed string.
fn as_ref(&self) -> &str {
self.0.as_str()
}
}
impl LastEventId {
/// Create a `LastEventId` with a static string.
///
/// # Panic
///
/// Panics if the string is not a legal header value.
#[must_use]
pub fn from_static(s: &'static str) -> Self {
Self(HeaderValueString::from_static(s))
}
}
rama_utils::macros::error::static_str_error! {
#[doc = "last-event-id is not valid"]
pub struct InvalidLastEventId;
}
impl FromStr for LastEventId {
type Err = InvalidLastEventId;
fn from_str(src: &str) -> Result<Self, Self::Err> {
HeaderValueString::from_str(src)
.map(LastEventId)
.map_err(|_e| InvalidLastEventId)
}
}
impl fmt::Display for LastEventId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}