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 copy of the value. Read more
1.0.0 · 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) -> Result<(), WebSocketError>

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 ) -> Result<(), WebSocketError>

Writes a DataFrame to a Writer.
source§

impl Debug for OwnedMessage

source§

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

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

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl From<String> for OwnedMessage

source§

fn from(text: String) -> OwnedMessage

Converts to this type from the input type.
source§

impl From<Vec<u8>> for OwnedMessage

source§

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

Converts to this type from the input type.
source§

impl Message for OwnedMessage

source§

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

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>) -> Result<OwnedMessage, WebSocketError>
where D: DataFrame,

Attempt to form a message from a series of data frames

source§

impl PartialEq for OwnedMessage

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for OwnedMessage

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> Typeable for T
where T: Any,

source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.