pub enum Message {
Text(Bytes),
Binary(Bytes),
Ping(Bytes),
Pong(Bytes),
Close(Option<CloseReason>),
}Expand description
WebSocket message (complete, possibly assembled from fragments)
Text messages use Bytes internally for zero-copy efficiency.
The payload is UTF-8 validated during parsing, so as_text() is safe.
Variants§
Text(Bytes)
Text message (UTF-8 validated, stored as Bytes for zero-copy)
Binary(Bytes)
Binary message
Ping(Bytes)
Ping message
Pong(Bytes)
Pong message
Close(Option<CloseReason>)
Close message
Implementations§
Source§impl Message
impl Message
Sourcepub fn is_control(&self) -> bool
pub fn is_control(&self) -> bool
Check if this is a control message
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Get message as text (returns None for non-text messages)
This is zero-copy - it returns a reference to the underlying bytes. The text is guaranteed to be valid UTF-8 as it was validated during parsing.
Sourcepub fn into_text(self) -> Option<String>
pub fn into_text(self) -> Option<String>
Convert to text message (allocates a String)
Returns None for non-text messages.
Sourcepub fn text_bytes(&self) -> Option<&Bytes>
pub fn text_bytes(&self) -> Option<&Bytes>
Get the underlying Bytes for text messages (zero-copy)
Returns None for non-text messages.
Sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Convert to binary data
Trait Implementations§
Source§impl<S> Sink<Message> for CompressedWebSocketStream<S>
Available on crate feature permessage-deflate only.
impl<S> Sink<Message> for CompressedWebSocketStream<S>
Available on crate feature
permessage-deflate only.Source§fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
Attempts to prepare the
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<()>
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<()>
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<S> Sink<Message> for WebSocketStream<S>
impl<S> Sink<Message> for WebSocketStream<S>
Source§fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
Attempts to prepare the
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<()>
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<()>
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 moreAuto 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