pub enum Message<'a> {
Text(&'a str),
Binary(&'a [u8]),
Ping(&'a [u8]),
Pong(&'a [u8]),
Close(CloseFrame<'a>),
}Expand description
A complete WebSocket message.
Text payloads are validated UTF-8. Close frames are parsed into structured code + reason. No continuation frames are exposed.
Borrows from the reader’s internal buffer — drop before calling
FrameReader::next() again.
Variants§
Text(&'a str)
UTF-8 text message (validated).
Binary(&'a [u8])
Binary message.
Ping(&'a [u8])
Ping control frame.
Pong(&'a [u8])
Pong control frame.
Close(CloseFrame<'a>)
Connection close.
Implementations§
Source§impl<'a> Message<'a>
impl<'a> Message<'a>
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Payload as bytes, regardless of message type.
Text→ UTF-8 bytesBinary/Ping/Pong→ raw bytesClose→ reason string as bytes (excludes the 2-byte status code)
Sourcepub fn into_bytes(self) -> &'a [u8] ⓘ
pub fn into_bytes(self) -> &'a [u8] ⓘ
Consume the message, returning the payload as a byte slice.
Releases the borrow on the FrameReader while keeping access
to the payload (valid until the reader is advanced).
Sourcepub fn into_owned(self) -> OwnedMessage
pub fn into_owned(self) -> OwnedMessage
Take ownership. Copies payload out of borrowed buffer.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Message<'a>
impl<'a> RefUnwindSafe for Message<'a>
impl<'a> Send for Message<'a>
impl<'a> Sync for Message<'a>
impl<'a> Unpin for Message<'a>
impl<'a> UnsafeUnpin for Message<'a>
impl<'a> UnwindSafe for Message<'a>
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