[][src]Enum websocket_base::message::OwnedMessage

pub enum OwnedMessage {
    Text(String),
    Binary(Vec<u8>),
    Close(Option<CloseData>),
    Ping(Vec<u8>),
    Pong(Vec<u8>),
}

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

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

impl OwnedMessage[src]

pub fn is_close(&self) -> bool[src]

Checks if this message is a close message.

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

pub fn is_control(&self) -> bool[src]

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

pub fn is_data(&self) -> bool[src]

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

pub fn is_ping(&self) -> bool[src]

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

pub fn is_pong(&self) -> bool[src]

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

impl Clone for OwnedMessage[src]

impl DataFrame for OwnedMessage[src]

impl Debug for OwnedMessage[src]

impl Eq for OwnedMessage[src]

impl<'m> From<Message<'m>> for OwnedMessage[src]

impl<'m> From<OwnedMessage> for Message<'m>[src]

impl From<String> for OwnedMessage[src]

impl From<Vec<u8>> for OwnedMessage[src]

impl Message for OwnedMessage[src]

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

Attempt to form a message from a series of data frames

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

Returns how many bytes this message will take up

fn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self> where
    D: DataFrameTrait
[src]

Attempt to form a message from a series of data frames

impl PartialEq<OwnedMessage> for OwnedMessage[src]

impl StructuralEq for OwnedMessage[src]

impl StructuralPartialEq for OwnedMessage[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.