[][src]Enum websockets::Frame

pub enum Frame {
    Text {
        payload: String,
        continuation: bool,
        fin: bool,
    },
    Binary {
        payload: Vec<u8>,
        continuation: bool,
        fin: bool,
    },
    Close {
        payload: Option<(u16, String)>,
    },
    Ping {
        payload: Option<Vec<u8>>,
    },
    Pong {
        payload: Option<Vec<u8>>,
    },
}

Data which is sent and received through the WebSocket connection.

Sending

To send a Frame, you can construct it normally and use the WebSocket::send() method, or use the convenience methods for each frame type (send_text(), send_binary(), close(), send_ping(), and send_pong()).

Receiving

Frames can be received through the WebSocket::receive() method. To extract the underlying data from a received Frame, you can use the convenience methods as_text(), as_binary(), as_close(), as_ping(), and as_pong(). (and their mut counterparts), or simply match.

Variants

Text

A Text frame

Fields of Text

payload: String

The payload for the Text frame

continuation: bool

Whether the Text frame is a continuation frame in the message

fin: bool

Whether the Text frame is the final frame in the message

Binary

A Binary frame

Fields of Binary

payload: Vec<u8>

The payload for the Binary frame

continuation: bool

Whether the Binary frame is a continuation frame in the message

fin: bool

Whether the Binary frame is the final frame in the message

Close

A Close frame

Fields of Close

payload: Option<(u16, String)>

The payload for the Close frame

Ping

A Ping frame

Fields of Ping

payload: Option<Vec<u8>>

The payload for the Ping frame

Pong

A Pong frame

Fields of Pong

payload: Option<Vec<u8>>

The payload for the Pong frame

Implementations

impl Frame[src]

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

Returns whether the frame is a Text frame.

pub fn as_text(&self) -> Option<(&String, &bool, &bool)>[src]

Attempts to interpret the frame as a Text frame, returning a reference to the underlying data if it is, and None otherwise.

pub fn as_text_mut(&mut self) -> Option<(&mut String, &mut bool, &mut bool)>[src]

Attempts to interpret the frame as a Text frame, returning a mutable reference to the underlying data if it is, and None otherwise.

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

Returns whether the frame is a Binary frame.

pub fn as_binary(&self) -> Option<(&Vec<u8>, &bool, &bool)>[src]

Attempts to interpret the frame as a Binary frame, returning a reference to the underlying data if it is, and None otherwise.

pub fn as_binary_mut(&mut self) -> Option<(&mut Vec<u8>, &mut bool, &mut bool)>[src]

Attempts to interpret the frame as a Binary frame, returning a mutable reference to the underlying data if it is, and None otherwise.

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

Returns whether the frame is a Close frame.

pub fn as_close(&self) -> Option<&(u16, String)>[src]

Attempts to interpret the frame as a Close frame, returning a reference to the underlying data if it is, and None otherwise.

pub fn as_close_mut(&mut self) -> Option<&mut (u16, String)>[src]

Attempts to interpret the frame as a Close frame, returning a mutable reference to the underlying data if it is, and None otherwise.

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

Returns whether the frame is a Ping frame.

pub fn as_ping(&self) -> Option<&Vec<u8>>[src]

Attempts to interpret the frame as a Ping frame, returning a reference to the underlying data if it is, and None otherwise.

pub fn as_ping_mut(&mut self) -> Option<&mut Vec<u8>>[src]

Attempts to interpret the frame as a Ping frame, returning a mutable reference to the underlying data if it is, and None otherwise.

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

Returns whether the frame is a Pong frame.

pub fn as_pong(&self) -> Option<&Vec<u8>>[src]

Attempts to interpret the frame as a Pong frame, returning a reference to the underlying data if it is, and None otherwise.

pub fn as_pong_mut(&mut self) -> Option<&mut Vec<u8>>[src]

Attempts to interpret the frame as a Pong frame, returning a mutable reference to the underlying data if it is, and None otherwise.

Trait Implementations

impl Debug for Frame[src]

Auto Trait Implementations

impl RefUnwindSafe for Frame

impl Send for Frame

impl Sync for Frame

impl Unpin for Frame

impl UnwindSafe for Frame

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

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,