Struct Frame

Source
pub struct Frame {
    pub fin: bool,
    pub rsv1: bool,
    pub rsv2: bool,
    pub rsv3: bool,
    pub opcode: OpCode,
    pub mask: Option<[u8; 4]>,
    pub payload: Vec<u8>,
}
Expand description

Represents a WebSocket frame.

Fields§

§fin: bool

Indicates if this is the final fragment in a message.

§rsv1: bool

First reserved bit.

§rsv2: bool

Second reserved bit.

§rsv3: bool

Third reserved bit.

§opcode: OpCode

The opcode for this frame.

§mask: Option<[u8; 4]>

The masking key, if any.

§payload: Vec<u8>

The payload data.

Implementations§

Source§

impl Frame

Source

pub fn new(opcode: OpCode, payload: Vec<u8>) -> Self

Creates a new Frame with the given opcode and payload.

Source

pub fn close(status_code: Option<u16>) -> Self

Creates a close frame with an optional status code.

Source

pub fn is_close(&self) -> bool

Checks if this frame is a close frame.

Source

pub fn is_masked(&self) -> bool

Checks if this frame is masked.

Source

pub async fn read_from<R: AsyncRead + Unpin>(reader: &mut R) -> Result<Self>

Reads a frame from the given AsyncRead stream.

§Errors

Returns an error if reading from the stream fails or if the frame is invalid.

Source

pub fn to_bytes(&self) -> Vec<u8>

Converts the frame to a byte vector.

Trait Implementations§

Source§

impl Debug for Frame

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnwindSafe for Frame

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

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V