[−][src]Struct seed::browser::web_socket::Builder
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.
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.
pub fn on_open<MsU: 'static>(
self,
handler: impl FnOnce() -> MsU + Clone + 'static
) -> Self
[src]
self,
handler: impl FnOnce() -> MsU + Clone + 'static
) -> Self
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.
pub fn on_close<MsU: 'static>(
self,
handler: impl FnOnce(CloseEvent) -> MsU + Clone + 'static
) -> Self
[src]
self,
handler: impl FnOnce(CloseEvent) -> MsU + Clone + 'static
) -> Self
Set on_close
Web Socket handler. The handler is called when connection's state changes
to State::Closed
.
pub fn on_error<MsU: 'static>(
self,
handler: impl FnOnce() -> MsU + Clone + 'static
) -> Self
[src]
self,
handler: impl FnOnce() -> MsU + Clone + 'static
) -> Self
Set on_error
Web Socket handler.
pub fn on_message<MsU: 'static>(
self,
handler: impl FnOnce(WebSocketMessage) -> MsU + Clone + 'static
) -> Self
[src]
self,
handler: impl FnOnce(WebSocketMessage) -> MsU + Clone + 'static
) -> Self
Set on_message
Web Socket handler. The handler is called when a message is received
from the server.
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,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut Tⓘ
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,