pub struct WebSocket { /* private fields */ }
Expand description
Wrapper around browser’s WebSocket API.
Implementations
sourceimpl WebSocket
impl WebSocket
sourcepub fn open(url: &str) -> Result<WebSocket, JsError>
pub fn open(url: &str) -> Result<WebSocket, JsError>
Establish a WebSocket connection.
This function may error in the following cases:
- The port to which the connection is being attempted is being blocked.
- The URL is invalid.
The error returned is [JsError
]. See the
MDN Documentation
to learn more.
sourcepub fn close(
self,
code: Option<u16>,
reason: Option<&str>
) -> Result<(), JsError>
pub fn close(
self,
code: Option<u16>,
reason: Option<&str>
) -> Result<(), JsError>
Closes the websocket.
See the MDN Documentation
to learn about parameters passed to this function and when it can return an Err(_)
sourcepub fn extensions(&self) -> String
pub fn extensions(&self) -> String
The extensions in use.
Trait Implementations
sourceimpl Sink<Message> for WebSocket
impl Sink<Message> for WebSocket
type Error = WebSocketError
type Error = WebSocketError
The type of value produced by the sink when an error occurs.
sourcefn poll_ready(
self: Pin<&mut WebSocket>,
cx: &mut Context<'_>
) -> Poll<Result<(), <WebSocket as Sink<Message>>::Error>>
fn poll_ready(
self: Pin<&mut WebSocket>,
cx: &mut Context<'_>
) -> Poll<Result<(), <WebSocket as Sink<Message>>::Error>>
Attempts to prepare the Sink
to receive a value. Read more
sourcefn start_send(
self: Pin<&mut WebSocket>,
item: Message
) -> Result<(), <WebSocket as Sink<Message>>::Error>
fn start_send(
self: Pin<&mut WebSocket>,
item: Message
) -> Result<(), <WebSocket as Sink<Message>>::Error>
Begin the process of sending a value to the sink.
Each call to this function must be preceded by a successful call to
poll_ready
which returned Poll::Ready(Ok(()))
. Read more
sourceimpl Stream for WebSocket
impl Stream for WebSocket
type Item = Result<Message, WebSocketError>
type Item = Result<Message, WebSocketError>
Values yielded by the stream.
impl<'pin> Unpin for WebSocket where
__WebSocket<'pin>: Unpin,
Auto Trait Implementations
impl !RefUnwindSafe for WebSocket
impl !Send for WebSocket
impl !Sync for WebSocket
impl !UnwindSafe for WebSocket
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more