Enum websocket_base::message::OwnedMessage
source · [−]pub enum OwnedMessage {
Text(String),
Binary(Vec<u8>),
Close(Option<CloseData>),
Ping(Vec<u8>),
Pong(Vec<u8>),
}
Expand description
Represents an owned WebSocket message.
OwnedMessage
s are generated when the user receives a message (since the data
has to be copied out of the network buffer anyway).
If you would like to create a message out of borrowed data to use for sending
please use the Message
struct (which contains a Cow
).
Note that OwnedMessage
and Message
can be converted into each other.
Variants
Text(String)
A message containing UTF-8 text data
Binary(Vec<u8>)
A message containing binary data
Close(Option<CloseData>)
A message which indicates closure of the WebSocket connection. This message may or may not contain data.
Ping(Vec<u8>)
A ping message - should be responded to with a pong message. Usually the pong message will be sent with the same data as the received ping message.
Pong(Vec<u8>)
A pong message, sent in response to a Ping message, usually containing the same data as the received ping message.
Implementations
sourceimpl OwnedMessage
impl OwnedMessage
sourcepub fn is_close(&self) -> bool
pub fn is_close(&self) -> bool
Checks if this message is a close message.
assert!(OwnedMessage::Close(None).is_close());
sourcepub fn is_control(&self) -> bool
pub fn is_control(&self) -> bool
Checks if this message is a control message.
Control messages are either Close
, Ping
, or Pong
.
assert!(OwnedMessage::Ping(vec![]).is_control());
assert!(OwnedMessage::Pong(vec![]).is_control());
assert!(OwnedMessage::Close(None).is_control());
sourcepub fn is_data(&self) -> bool
pub fn is_data(&self) -> bool
Checks if this message is a data message.
Data messages are either Text
or Binary
.
assert!(OwnedMessage::Text("1337".to_string()).is_data());
assert!(OwnedMessage::Binary(vec![]).is_data());
Trait Implementations
sourceimpl Clone for OwnedMessage
impl Clone for OwnedMessage
sourcefn clone(&self) -> OwnedMessage
fn clone(&self) -> OwnedMessage
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl DataFrame for OwnedMessage
impl DataFrame for OwnedMessage
sourcefn write_payload(&self, socket: &mut dyn Write) -> WebSocketResult<()>
fn write_payload(&self, socket: &mut dyn Write) -> WebSocketResult<()>
Write the payload to a writer
sourcefn take_payload(self) -> Vec<u8>
fn take_payload(self) -> Vec<u8>
Takes the payload out into a vec
sourcefn frame_size(&self, masked: bool) -> usize
fn frame_size(&self, masked: bool) -> usize
Get’s the size of the entire dataframe in bytes, i.e. header and payload. Read more
sourceimpl Debug for OwnedMessage
impl Debug for OwnedMessage
sourceimpl<'m> From<Message<'m>> for OwnedMessage
impl<'m> From<Message<'m>> for OwnedMessage
sourceimpl<'m> From<OwnedMessage> for Message<'m>
impl<'m> From<OwnedMessage> for Message<'m>
sourcefn from(message: OwnedMessage) -> Self
fn from(message: OwnedMessage) -> Self
Converts to this type from the input type.
sourceimpl From<String> for OwnedMessage
impl From<String> for OwnedMessage
sourceimpl Message for OwnedMessage
impl Message for OwnedMessage
sourcefn serialize(&self, writer: &mut dyn Write, masked: bool) -> WebSocketResult<()>
fn serialize(&self, writer: &mut dyn Write, masked: bool) -> WebSocketResult<()>
Attempt to form a message from a series of data frames
sourcefn message_size(&self, masked: bool) -> usize
fn message_size(&self, masked: bool) -> usize
Returns how many bytes this message will take up
sourcefn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self> where
D: DataFrameTrait,
fn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self> where
D: DataFrameTrait,
Attempt to form a message from a series of data frames
sourceimpl PartialEq<OwnedMessage> for OwnedMessage
impl PartialEq<OwnedMessage> for OwnedMessage
sourcefn eq(&self, other: &OwnedMessage) -> bool
fn eq(&self, other: &OwnedMessage) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &OwnedMessage) -> bool
fn ne(&self, other: &OwnedMessage) -> bool
This method tests for !=
.
impl Eq for OwnedMessage
impl StructuralEq for OwnedMessage
impl StructuralPartialEq for OwnedMessage
Auto Trait Implementations
impl RefUnwindSafe for OwnedMessage
impl Send for OwnedMessage
impl Sync for OwnedMessage
impl Unpin for OwnedMessage
impl UnwindSafe for OwnedMessage
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more