pub enum Message {
Text(String),
Binary(Vec<u8>),
Ping(Vec<u8>),
Pong(Vec<u8>),
Close(Option<CloseFrame>),
}Variants§
Text(String)
Binary(Vec<u8>)
Ping(Vec<u8>)
Pong(Vec<u8>)
Close(Option<CloseFrame>)
None when the peer closed without a status code, which is legal.
Implementations§
Source§impl Message
impl Message
pub fn text(body: impl Into<String>) -> Message
Sourcepub fn json(value: &Json) -> Message
pub fn json(value: &Json) -> Message
A JSON message. The broadcasting protocol is built entirely out of these.
pub fn close(code: CloseCode, reason: impl Into<String>) -> Message
pub fn as_text(&self) -> Option<&str>
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn is_data(&self) -> bool
pub fn is_data(&self) -> bool
Text or binary — the messages an application actually cares about.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn kind(&self) -> &'static str
pub fn kind(&self) -> &'static str
A stable label for instrumentation. Never the payload itself: a socket carrying chat or auth tokens must not leak them into Telescope.
Sourcepub fn into_frame(self) -> Frame
pub fn into_frame(self) -> Frame
The frame a server writes for this message: final, and never masked.
Sourcepub fn from_data(opcode: OpCode, payload: Vec<u8>) -> WsResult<Message>
pub fn from_data(opcode: OpCode, payload: Vec<u8>) -> WsResult<Message>
Turn a reassembled payload into a message.
Text is validated here rather than at the frame layer, because a message split across fragments is only valid UTF-8 once every fragment has arrived — a multi-byte character is allowed to straddle the boundary.
Trait Implementations§
impl 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 UnsafeUnpin 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