pub struct Message { /* private fields */ }
Expand description
A WebSocket message.
This will likely become a non-exhaustive
enum in the future, once that
language feature has stabilized.
Implementations§
source§impl Message
impl Message
sourcepub fn pong<V: Into<Vec<u8>>>(v: V) -> Message
pub fn pong<V: Into<Vec<u8>>>(v: V) -> Message
Construct a new Pong Message
.
Note that one rarely needs to manually construct a Pong message because the underlying tungstenite socket automatically responds to the Ping messages it receives. Manual construction might still be useful in some cases like in tests or to send unidirectional heartbeats.
sourcepub fn close_with(
code: impl Into<u16>,
reason: impl Into<Cow<'static, str>>,
) -> Message
pub fn close_with( code: impl Into<u16>, reason: impl Into<Cow<'static, str>>, ) -> Message
Construct a Close Message
with a code and reason.
sourcepub fn close_frame(&self) -> Option<(u16, &str)>
pub fn close_frame(&self) -> Option<(u16, &str)>
Try to get the close frame (close code and reason)
sourcepub fn to_str(&self) -> Result<&str, ()>
pub fn to_str(&self) -> Result<&str, ()>
Try to get a reference to the string text, if this is a Text message.
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Return the bytes of this message, if the message can contain data.
sourcepub fn into_bytes(self) -> Vec<u8>
pub fn into_bytes(self) -> Vec<u8>
Destructure this message into binary data.
Trait Implementations§
source§impl Sink<Message> for WebSocket
impl Sink<Message> for WebSocket
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Attempts to prepare the
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::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 Sink<Message> for WsClient
impl Sink<Message> for WsClient
source§fn poll_ready(
self: Pin<&mut Self>,
context: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, context: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Attempts to prepare the
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, message: Message) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, message: Message) -> Result<(), Self::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 moreimpl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.