pub enum WsEvent {
    Error(Arc<WsErr>),
    CloseFrame(Option<CloseFrame<'static>>),
    Ping(Vec<u8>),
    Pong(Vec<u8>),
    Closed,
}
Expand description

Events that can happen on the websocket. These are returned through the stream you can obtain from WsStream::observe. These include close, ping and pong events which can not be returned through AsyncRead/AsyncWrite, and non-fatal errors.

Variants§

§

Error(Arc<WsErr>)

Non fatal error that happened on the websocket. Non-fatal here doesn’t mean the websocket is still usable, but at least is still usable enough to initiate a close handshake. If we bubble up errors through AsyncRead/AsyncWrite, codecs will always return None on subsequent polls, which would prevent from driving the close handshake to completion. Hence they are returned out of band.

§

CloseFrame(Option<CloseFrame<'static>>)

We received a close frame from the remote. Just keep polling the stream. The close handshake will be completed for you. Once the stream returns None, you can drop the WsStream. This is mainly useful in order to recover the close code and reason for debugging purposes.

§

Ping(Vec<u8>)

The remote sent a Ping message. It will automatically be answered as long as you keep polling the AsyncRead. This is returned as an event in case you want to analyze the payload, since only bytes from Binary websocket messages are passed through the AsyncRead.

§

Pong(Vec<u8>)

The remote send us a Pong. Since we never send Pings, this is a unidirectional heartbeat.

§

Closed

The connection is closed. Polling WsStream will return None on read and io::ErrorKind::NotConnected on write soon. It’s provided here for convenience so the task listening to these events know that the connection closed. You should not see any events after this one, so you can drop the Events stream.

Trait Implementations§

source§

impl Clone for WsEvent

source§

fn clone(&self) -> WsEvent

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for WsEvent

source§

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

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

impl<S> Observable<WsEvent> for WsStream<S>
where S: AsyncRead + AsyncWrite + Send + Unpin,

§

type Error = WsErr

The error type that is returned if observing is not possible. Read more
source§

fn observe( &mut self, options: ObserveConfig<WsEvent> ) -> Observe<'_, WsEvent, Self::Error>

Add an observer to the observable. Options allow chosing the channel type and to filter events with a predicate.

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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

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