Skip to main content

SessionEvent

Enum SessionEvent 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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: DisconnectReason

Why it stopped.

§retry_in: Option<Duration>

How long until the next attempt, or None when there will not be one.

§

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.

Fields

§reason: String

Why the request could not be sent.

§

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.

Fields

§line: String

The line exactly as it arrived, with its terminator stripped.

§

Closed(ClosedReason)

Terminal. The session is over and no further event will arrive.

Trait Implementations§

Source§

impl Clone for SessionEvent

Source§

fn clone(&self) -> SessionEvent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SessionEvent

Source§

impl PartialEq for SessionEvent

Source§

fn eq(&self, other: &SessionEvent) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SessionEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more