Struct Event
pub struct Event<T = String> { /* private fields */ }
Expand description
Server-sent event
Implementations§
§impl<T> Event<T>
impl<T> Event<T>
pub fn id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
Return the event’s identifier field (id:<identifier>
).
This corresponds to MessageEvent
’s lastEventId
field. If no ID is in the event itself,
the browser will set that field to the last known message ID, starting with the empty
string.
pub fn try_with_id(
self,
id: impl Into<SmolStr>,
) -> Result<Event<T>, EventBuildError>
pub fn try_with_id( self, id: impl Into<SmolStr>, ) -> Result<Event<T>, EventBuildError>
Set the event’s identifier field (id:<identifier>
).
This corresponds to MessageEvent
’s lastEventId
field. If no ID is in the event itself,
the browser will set that field to the last known message ID, starting with the empty
string.
Previously set value will be overwritten.
pub fn try_set_id(
&mut self,
id: impl Into<SmolStr>,
) -> Result<&mut Event<T>, EventBuildError>
pub fn try_set_id( &mut self, id: impl Into<SmolStr>, ) -> Result<&mut Event<T>, EventBuildError>
Set the event’s identifier field (id:<identifier>
).
This corresponds to MessageEvent
’s lastEventId
field. If no ID is in the event itself,
the browser will set that field to the last known message ID, starting with the empty
string.
Previously set value will be overwritten.
pub fn data(&self) -> Option<&T>
pub fn data(&self) -> Option<&T>
Return the event’s data data field(s) (data: <content>
)
This corresponds to MessageEvent
’s data field.
pub fn into_data(self) -> Option<T>
pub fn into_data(self) -> Option<T>
Consume self
and return the event’s data data field(s) (data: <content>
)
This corresponds to MessageEvent
’s data field.
pub fn with_data(self, data: T) -> Event<T>
pub fn with_data(self, data: T) -> Event<T>
Set the event’s data data field(s) (data: <content>
)
The serialized data will automatically break newlines across data:
fields.
This corresponds to MessageEvent
’s data field.
Note that events with an empty data field will be ignored by the browser. Previously set value will be overwritten.
pub fn set_data(&mut self, data: T) -> &mut Event<T>
pub fn set_data(&mut self, data: T) -> &mut Event<T>
Set the event’s data data field(s) (data: <content>
)
The serialized data will automatically break newlines across data:
fields.
This corresponds to MessageEvent
’s data field.
Note that events with an empty data field will be ignored by the browser. Previously set value will be overwritten.
pub fn event(&self) -> Option<&str>
pub fn event(&self) -> Option<&str>
Return the event’s name field (event:<event-name>
).
This corresponds to the type
parameter given when calling addEventListener
on an
EventSource
. For example, .event("update")
should correspond to
.addEventListener("update", ...)
. If no event type is given, browsers will fire a
message
event instead.
pub fn try_with_event(
self,
event: impl Into<SmolStr>,
) -> Result<Event<T>, EventBuildError>
pub fn try_with_event( self, event: impl Into<SmolStr>, ) -> Result<Event<T>, EventBuildError>
Set the event’s name field (event:<event-name>
).
Previously set event will be overwritten.
This corresponds to the type
parameter given when calling addEventListener
on an
EventSource
. For example, .event("update")
should correspond to
.addEventListener("update", ...)
. If no event type is given, browsers will fire a
message
event instead.
pub fn try_set_event(
&mut self,
event: impl Into<SmolStr>,
) -> Result<&mut Event<T>, EventBuildError>
pub fn try_set_event( &mut self, event: impl Into<SmolStr>, ) -> Result<&mut Event<T>, EventBuildError>
Set the event’s name field (event:<event-name>
).
Previously set event will be overwritten.
This corresponds to the type
parameter given when calling addEventListener
on an
EventSource
. For example, .event("update")
should correspond to
.addEventListener("update", ...)
. If no event type is given, browsers will fire a
message
event instead.
pub fn retry(&self) -> Option<Duration>
pub fn retry(&self) -> Option<Duration>
Return the event’s retry timeout field (retry:<timeout>
).
This sets how long clients will wait before reconnecting if they are disconnected from the SSE endpoint. Note that this is just a hint: clients are free to wait for longer if they wish, such as if they implement exponential backoff.
pub const fn with_static_retry(self, millis: u64) -> Event<T>
pub const fn with_static_retry(self, millis: u64) -> Event<T>
Set the event’s retry timeout field (retry:<timeout>
).
Previously set retry will be overwritten.
This sets how long clients will wait before reconnecting if they are disconnected from the SSE endpoint. Note that this is just a hint: clients are free to wait for longer if they wish, such as if they implement exponential backoff.
pub fn with_retry(self, millis: u64) -> Event<T>
pub fn with_retry(self, millis: u64) -> Event<T>
Set the event’s retry timeout field (retry:<timeout>
).
Previously set retry will be overwritten.
This sets how long clients will wait before reconnecting if they are disconnected from the SSE endpoint. Note that this is just a hint: clients are free to wait for longer if they wish, such as if they implement exponential backoff.
pub fn set_retry(&mut self, millis: u64) -> &mut Event<T>
pub fn set_retry(&mut self, millis: u64) -> &mut Event<T>
Set the event’s retry timeout field (retry:<timeout>
).
Previously set retry will be overwritten.
This sets how long clients will wait before reconnecting if they are disconnected from the SSE endpoint. Note that this is just a hint: clients are free to wait for longer if they wish, such as if they implement exponential backoff.
pub fn comment(&self) -> impl Iterator<Item = &str>
pub fn comment(&self) -> impl Iterator<Item = &str>
Return the event’s comment fields (:<comment-text>
).
pub fn try_with_comment(
self,
comment: impl Into<SmolStr>,
) -> Result<Event<T>, EventBuildError>
pub fn try_with_comment( self, comment: impl Into<SmolStr>, ) -> Result<Event<T>, EventBuildError>
Set the event’s comment field (:<comment-text>
).
This field will be ignored by most SSE clients.
You can add as many comments as you want by calling this function as many as you wish, unlike other setters this one does not overwrite.
pub fn try_set_comment(
&mut self,
comment: impl Into<SmolStr>,
) -> Result<&mut Event<T>, EventBuildError>
pub fn try_set_comment( &mut self, comment: impl Into<SmolStr>, ) -> Result<&mut Event<T>, EventBuildError>
Set the event’s comment field (:<comment-text>
).
This field will be ignored by most SSE clients.
You can add as many comments as you want by calling this function as many as you wish, unlike other setters this one does not overwrite.
§impl Event
impl Event
pub fn try_with_json_data(
self,
data: impl Serialize,
) -> Result<Event, OpaqueError>
pub fn try_with_json_data( self, data: impl Serialize, ) -> Result<Event, OpaqueError>
Use JsonEventData
as a shortcut to serialize it directly
into a String
using Self::data
.
pub fn try_set_json_data(
&mut self,
data: impl Serialize,
) -> Result<&mut Event, OpaqueError>
pub fn try_set_json_data( &mut self, data: impl Serialize, ) -> Result<&mut Event, OpaqueError>
Use JsonEventData
as a shortcut to serialize it directly
into a String
using Self::data
.
Trait Implementations§
§impl<T> From<ExecuteScript> for Event<EventData<T>>
impl<T> From<ExecuteScript> for Event<EventData<T>>
§fn from(value: ExecuteScript) -> Event<EventData<T>>
fn from(value: ExecuteScript) -> Event<EventData<T>>
§impl From<ExecuteScript> for Event<ExecuteScript>
impl From<ExecuteScript> for Event<ExecuteScript>
§fn from(value: ExecuteScript) -> Event<ExecuteScript>
fn from(value: ExecuteScript) -> Event<ExecuteScript>
§impl<T> From<PatchElements> for Event<EventData<T>>
impl<T> From<PatchElements> for Event<EventData<T>>
§fn from(value: PatchElements) -> Event<EventData<T>>
fn from(value: PatchElements) -> Event<EventData<T>>
§impl From<PatchElements> for Event<PatchElements>
impl From<PatchElements> for Event<PatchElements>
§fn from(value: PatchElements) -> Event<PatchElements>
fn from(value: PatchElements) -> Event<PatchElements>
§impl<T> From<PatchSignals<T>> for Event<EventData<T>>
impl<T> From<PatchSignals<T>> for Event<EventData<T>>
§fn from(value: PatchSignals<T>) -> Event<EventData<T>>
fn from(value: PatchSignals<T>) -> Event<EventData<T>>
§impl<T> From<PatchSignals<T>> for Event<PatchSignals<T>>
impl<T> From<PatchSignals<T>> for Event<PatchSignals<T>>
§fn from(value: PatchSignals<T>) -> Event<PatchSignals<T>>
fn from(value: PatchSignals<T>) -> Event<PatchSignals<T>>
impl<T> Eq for Event<T>where
T: Eq,
Auto Trait Implementations§
impl<T> Freeze for Event<T>where
T: Freeze,
impl<T> RefUnwindSafe for Event<T>where
T: RefUnwindSafe,
impl<T> Send for Event<T>where
T: Send,
impl<T> Sync for Event<T>where
T: Sync,
impl<T> Unpin for Event<T>where
T: Unpin,
impl<T> UnwindSafe for Event<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more