Skip to main content

OwnedMessage

Enum 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.

OwnedMessages 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§

Source§

impl OwnedMessage

Source

pub fn is_close(&self) -> bool

Checks if this message is a close message.

assert!(OwnedMessage::Close(None).is_close());
Source

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());
Source

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());
Source

pub fn is_ping(&self) -> bool

Checks if this message is a ping message. Ping messages can come at any time and usually generate a Pong message response.

assert!(OwnedMessage::Ping("ping".to_string().into_bytes()).is_ping());
Source

pub fn is_pong(&self) -> bool

Checks if this message is a pong message. Pong messages are usually sent only in response to Ping messages.

assert!(OwnedMessage::Pong("pong".to_string().into_bytes()).is_pong());

Trait Implementations§

Source§

impl Clone for OwnedMessage

Source§

fn clone(&self) -> OwnedMessage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DataFrame for OwnedMessage

Source§

fn is_last(&self) -> bool

Is this dataframe the final dataframe of the message?
Source§

fn opcode(&self) -> u8

What type of data does this dataframe contain?
Source§

fn reserved(&self) -> &[bool; 3]

Reserved bits of this dataframe
Source§

fn size(&self) -> usize

How long (in bytes) is this dataframe’s payload
Source§

fn write_payload(&self, socket: &mut dyn Write) -> WebSocketResult<()>

Write the payload to a writer
Source§

fn take_payload(self) -> Vec<u8>

Takes the payload out into a vec
Source§

fn frame_size(&self, masked: bool) -> usize

Get’s the size of the entire dataframe in bytes, i.e. header and payload.
Source§

fn write_to(&self, writer: &mut dyn Write, mask: bool) -> WebSocketResult<()>

Writes a DataFrame to a Writer.
Source§

impl Debug for OwnedMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for OwnedMessage

Source§

impl<'m> From<Message<'m>> for OwnedMessage

Source§

fn from(message: Message<'m>) -> Self

Converts to this type from the input type.
Source§

impl<'m> From<OwnedMessage> for Message<'m>

Source§

fn from(message: OwnedMessage) -> Self

Converts to this type from the input type.
Source§

impl From<String> for OwnedMessage

Source§

fn from(text: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for OwnedMessage

Source§

fn from(buf: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl Message for OwnedMessage

Source§

fn serialize(&self, writer: &mut dyn Write, masked: bool) -> WebSocketResult<()>

Attempt to form a message from a series of data frames

Source§

fn message_size(&self, masked: bool) -> usize

Returns how many bytes this message will take up

Source§

fn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self>
where D: DataFrameTrait,

Attempt to form a message from a series of data frames

Source§

impl PartialEq for OwnedMessage

Source§

fn eq(&self, other: &OwnedMessage) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OwnedMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.