Enum Frame

Source
pub enum Frame {
Show 15 variants SimpleString(String), SimpleError(String), Integer(i64), BulkString(Bytes), Array(Vec<Frame>), Null, Boolean(bool), Double(f64), BigNumber(BigInt), BulkError(Bytes), VerbatimString(Bytes, Bytes), Map(Vec<(Frame, Frame)>), Attribute, Set(Vec<Frame>), Push,
}
Expand description

Frame represents a single RESP data transmit unit over the socket.

more on the RESP protocol can be found here

Variants§

§

SimpleString(String)

§

SimpleError(String)

§

Integer(i64)

§

BulkString(Bytes)

§

Array(Vec<Frame>)

§

Null

§

Boolean(bool)

§

Double(f64)

§

BigNumber(BigInt)

§

BulkError(Bytes)

§

VerbatimString(Bytes, Bytes)

§

Map(Vec<(Frame, Frame)>)

§

Attribute

§

Set(Vec<Frame>)

§

Push

Implementations§

Source§

impl Frame

Source

pub const fn array() -> Self

Returns an empty Array Frame.

Source

pub fn push_frame_to_array(&mut self, frame: Frame) -> Result<()>

A utility method to push a Frame into an Array/Set Frame.

§Arguments
  • frame - A Frame to be pushed into the Array
§Panics

This method will panic if the Frame is not an Array or Set.

Source

pub fn push_frame_to_map(&mut self, key: Frame, value: Frame) -> Result<()>

A utility method to push a Frame into a Map Frame.

§Arguments
  • key - A Frame to be used as a key in the Map
  • value - A Frame to be used as a value in the Map
§Panics

This method will panic if the Frame is not a Map.

Source

pub async fn serialize(&self) -> Result<Bytes>

Serializes a Frame into a bytes buffer.

The returned value is a smart pointer only counting reference. It is cheap to clone. Caller can get the underlying slice by calling as_slice or as_ref on the returned value. It is almost 0 cost to get the slice.

§Returns

A Result containing the serialized bytes buffer

Source

pub async fn deserialize(buf: Bytes) -> Result<Frame>

Deserializes from the buffer into a Frame.

The method reads from the buffer and parses it into a Frame.

§Arguments
  • buf - An immutable read buffer containing the serialized Frame
§Returns

A Result containing the deserialized Frame

Source

pub fn try_parse(cursor: &mut Cursor<&[u8]>) -> Result<Frame>

Tries parsing a Frame from the buffer.

This method wraps the input with a cursor to track the current version as we need to make resursive calls. Using a cursor avoids the need to split the buffer or passing an additional parameter.

§Returns
  • Ok(usize) if the buffer contains a complete frame, the number of bytes needed to parse the frame
  • Err(RedisError::IncompleteFrame) if the buffer contains an incomplete frame
  • Err(RedisError::InvalidFrame) if the buffer contains an invalid frame

Trait Implementations§

Source§

impl Debug for Frame

Source§

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

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

impl PartialEq for Frame

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Frame

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