pub struct WebSocket { /* private fields */ }
Expand description
Wrapper around browser’s WebSocket API.
Implementations§
Source§impl 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§
Source§impl Sink<Message> for WebSocket
impl Sink<Message> for WebSocket
Source§type Error = WebSocketError
type Error = WebSocketError
The type of value produced by the sink when an error occurs.
Source§fn 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 moreSource§fn 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 moreSource§impl Stream for WebSocket
impl Stream for WebSocket
impl<'pin> Unpin for WebSocketwhere
<PinnedFieldsOfHelperStruct<__WebSocket<'pin>> as PinnedFieldsOfHelperTrait>::Actual: Unpin,
Auto Trait Implementations§
impl Freeze for WebSocket
impl !RefUnwindSafe for WebSocket
impl !Send for WebSocket
impl !Sync for WebSocket
impl !UnwindSafe for WebSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more