[][src]Struct ws_stream_wasm::WsStream

pub struct WsStream { /* fields omitted */ }

A futures 0.3 Sink/Stream of WsMessage. Created with WsMeta::connect.

Closing the connection

When this is dropped, the connection closes, but you should favor calling one of the close methods on WsMeta, which allow you to set a proper close code and reason.

Since this implements Sink, it has to have a close method. This method will call the web api WebSocket.close without parameters. Eg. a default value of 1005 will be assumed for the close code. The situation is the same when dropping without calling close.

Warning: This object holds the callbacks needed to receive events from the browser. If you drop it before the close event was emitted, you will no longer receive events. Thus, observers will never receive a Close event. Drop will issue a Closing event and this will be the very last event observers receive. The the stream will end if WsMeta is also dropped.

See the integration tests if you need an example.

Implementations

impl WsStream[src]

pub fn ready_state(&self) -> WsState[src]

Verify the WsState of the connection.

pub fn wrapped(&self) -> &WebSocket[src]

Access the wrapped web_sys::WebSocket directly.

ws_stream_wasm tries to expose all useful functionality through an idiomatic rust API, so hopefully you won't need this, however if I missed something, you can.

Caveats

If you call set_onopen, set_onerror, set_onmessage or set_onclose on this, you will overwrite the event listeners from ws_stream_wasm, and things will break.

pub fn into_io(self) -> IoStream<WsStreamIo, Vec<u8>>[src]

Wrap this object in IoStream. IoStream implements AsyncRead/AsyncWrite/AsyncBufRead. Beware: that this will transparenty include text messages as bytes.

Trait Implementations

impl Debug for WsStream[src]

impl Drop for WsStream[src]

impl Sink<WsMessage> for WsStream[src]

type Error = WsErr

The type of value produced by the sink when an error occurs.

impl Stream for WsStream[src]

type Item = WsMessage

Values yielded by the stream.

Auto Trait Implementations

impl !RefUnwindSafe for WsStream

impl Send for WsStream

impl Sync for WsStream

impl Unpin for WsStream

impl !UnwindSafe for WsStream

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Item> SinkExt<Item> for T where
    T: Sink<Item> + ?Sized
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.