[][src]Struct seed::browser::web_socket::Builder

pub struct Builder<'a, U: AsRef<str>, Ms: 'static, O: Orders<Ms>> { /* fields omitted */ }

Builder creates a new WebSocket instance.

Example

enum Msg { MessageReceived(WebSocketMessage) }
...
let web_socket = WebSocket::builder("ws://127.0.0.1:9000/ws", orders)
    .on_message(Msg::MessageReceived)
    .build_and_open();

Implementations

impl<'a, U: AsRef<str>, Ms: 'static, O: Orders<Ms>> Builder<'a, U, Ms, O>[src]

pub fn protocols(self, protocols: &'a [&'a str]) -> Self[src]

Set preferred Web Socket sub-protocols.

MDN reference

pub fn use_array_buffers(self) -> Self[src]

Set binary data type to ArrayBuffer.

Notes::

  • Default binary type is Blob.
  • For small binary messages, like CBOR, ArrayBuffer is more efficient than Blob handling.

MDN reference

pub fn on_open<MsU: 'static>(
    self,
    handler: impl FnOnce() -> MsU + Clone + 'static
) -> Self
[src]

Set on_open Web Socket handler. The handler is called when connection's state changes to State::Open; this indicates that the connection is ready to send and receive data.

MDN reference

pub fn on_close<MsU: 'static>(
    self,
    handler: impl FnOnce(CloseEvent) -> MsU + Clone + 'static
) -> Self
[src]

Set on_close Web Socket handler. The handler is called when connection's state changes to State::Closed.

MDN reference

pub fn on_error<MsU: 'static>(
    self,
    handler: impl FnOnce() -> MsU + Clone + 'static
) -> Self
[src]

Set on_error Web Socket handler.

MDN reference

pub fn on_message<MsU: 'static>(
    self,
    handler: impl FnOnce(WebSocketMessage) -> MsU + Clone + 'static
) -> Self
[src]

Set on_message Web Socket handler. The handler is called when a message is received from the server.

MDN reference

pub fn build_and_open(self) -> Result<WebSocket>[src]

Create a new WebSocket instance from the Builder and try to open it.

Errors

Returns WebSocketError::OpenError when Web Socket opening fails. E.g. when the chosen port is blocked.

Note:: It doesn't return error when the socket is open on the client side, but fails to connect to the server - use on_error handler to resolve such cases.

Auto Trait Implementations

impl<'a, U, Ms, O> !RefUnwindSafe for Builder<'a, U, Ms, O>

impl<'a, U, Ms, O> !Send for Builder<'a, U, Ms, O>

impl<'a, U, Ms, O> !Sync for Builder<'a, U, Ms, O>

impl<'a, U, Ms, O> Unpin for Builder<'a, U, Ms, O> where
    Ms: Unpin,
    U: Unpin

impl<'a, U, Ms, O> !UnwindSafe for Builder<'a, U, Ms, O>

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

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