pub enum Message {
Text(String),
Binary(Vec<u8>),
Close(Option<String>),
}Expand description
One WebSocket frame’s payload.
Ping and pong are not here. They are keep-alive, the transport answers them, and a handler that had to remember to reply to a ping would have a connection that dies when it forgets.
Variants§
Text(String)
A text frame. UTF-8 by definition of the protocol.
Binary(Vec<u8>)
A binary frame.
Close(Option<String>)
The peer is closing, with an optional reason.
Delivered to on_message only if
a handler asked for it; on_close
is the usual place.
Implementations§
Source§impl Message
impl Message
Sourcepub fn json(value: &impl Serialize) -> Result<Self>
pub fn json(value: &impl Serialize) -> Result<Self>
A text frame holding value as JSON — how nearly every application
actually talks over a socket.
Sourcepub fn parse_json(&self) -> Result<Value>
pub fn parse_json(&self) -> Result<Value>
Parse a text frame as JSON.
A bad request, not an internal error: the bytes came from a client, and a client that sends nonsense is not a bug in your handler.
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