#[non_exhaustive]pub enum SessionEvent {
Connected(Box<Connected>),
Recovered(Recovery),
Resubscribed(Vec<Resubscribed>),
Disconnected {
reason: DisconnectReason,
retry_in: Option<Duration>,
},
Message(Box<MessageOutcome>),
ServerInfo(ServerInfo),
RequestRejected(ServerError),
RequestNotSent {
reason: String,
},
Unrecognized {
line: String,
},
Closed(ClosedReason),
}Expand description
Everything the client tells you about the session.
Delivered by SessionEvents. The enum is closed
but #[non_exhaustive]: match it exhaustively with a _ arm, and a future
version adding a variant will not break your build.
§Examples
use futures_util::StreamExt;
use lightstreamer_rs::{SessionEvent, StateValidity};
while let Some(event) = events.next().await {
match event {
SessionEvent::Connected(connected) => match connected.continuity.state_validity() {
// Keep what you computed: the same session came back intact.
StateValidity::Valid => {}
// A recovery is in flight; the next event says whether it lost
// anything. Decide then.
StateValidity::Pending => {}
// Nothing carries over: rebuild from the snapshots that follow.
StateValidity::Invalid => {}
_ => {}
},
SessionEvent::Closed(reason) => {
tracing::error!(?reason, "session is over");
break;
}
_ => {}
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Connected(Box<Connected>)
The session is bound to a server and streaming. Read
Connected::continuity to learn whether your derived state survived.
Recovered(Recovery)
A recovery reported where the flow resumed. Always follows a
SessionEvent::Connected carrying Continuity::Recovered.
Resubscribed(Vec<Resubscribed>)
Subscriptions were re-created on a newly bound session.
Emitted whenever any subscription had to be issued at bind time, which
after a session replacement is all of them. Your
Updates streams keep working across this; the event
exists so you know a fresh snapshot is on its way.
Disconnected
The session stopped streaming. A reconnection is already scheduled
unless retry_in is None, which means the client is about to give up
and a SessionEvent::Closed follows.
Fields
reason: DisconnectReasonWhy it stopped.
Message(Box<MessageOutcome>)
What became of a message you sent with
Client::send_message
[docs/spec/03-requests.md §12].
Only ever arrives for a message that carried a progressive; a fire-and-forget one is reported here only if it never left this client or the server refused the request outright.
ServerInfo(ServerInfo)
The server said something diagnostic.
RequestRejected(ServerError)
The server refused a control request, with a code from Appendix B
[docs/spec/05-error-codes.md §2]. The session is unaffected.
A refused subscription request is reported on that subscription’s
own stream instead, as
SubscriptionEvent::Rejected,
which is where you are looking for it. What lands here is everything
else:
- a refused unsubscription or reconfiguration — note that in both cases the subscription is still active; it is your request to change it that failed, not the subscription that died, and its stream keeps delivering;
- a refused request that belongs to the session as a whole;
- a refusal the server sent with no identifier at all, which the
protocol allows when it could not parse the request
[
docs/spec/03-requests.md§13.2].
Every ServerError carried here is something a server actually said.
A request that failed before reaching one is
SessionEvent::RequestNotSent instead.
RequestNotSent
A control request never reached the server, so no server refused it.
This is a local failure — the connection was down, or the request
could not be encoded — and it is deliberately not a ServerError.
Giving it a fabricated code would be indistinguishable from a code the
server’s Metadata Adapter supplied
(see ServerError::is_adapter_defined), which is a claim this crate
is in no position to make.
Subscription requests are exempt: an add that never left is reported
on the subscription’s own stream as
SubscriptionEvent::Deferred,
because it is still coming.
Unrecognized
A line arrived that this client could not parse.
Never fatal, and deliberately surfaced rather than swallowed: a server newer than this crate must not be able to break it, and you should be able to see that it happened.
Closed(ClosedReason)
Terminal. The session is over and no further event will arrive.
Trait Implementations§
Source§impl Clone for SessionEvent
impl Clone for SessionEvent
Source§fn clone(&self) -> SessionEvent
fn clone(&self) -> SessionEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more