Enum Frame

Source
pub enum Frame {
Show 16 variants BlobString { data: Bytes, attributes: Option<Attributes>, }, BlobError { data: Bytes, attributes: Option<Attributes>, }, SimpleString { data: Bytes, attributes: Option<Attributes>, }, SimpleError { data: Str, attributes: Option<Attributes>, }, Boolean { data: bool, attributes: Option<Attributes>, }, Null, Number { data: i64, attributes: Option<Attributes>, }, Double { data: f64, attributes: Option<Attributes>, }, BigNumber { data: Bytes, attributes: Option<Attributes>, }, VerbatimString { data: Bytes, format: VerbatimStringFormat, attributes: Option<Attributes>, }, Array { data: Vec<Frame>, attributes: Option<Attributes>, }, Map { data: FrameMap, attributes: Option<Attributes>, }, Set { data: FrameSet, attributes: Option<Attributes>, }, Push { data: Vec<Frame>, attributes: Option<Attributes>, }, Hello { version: RespVersion, auth: Option<Auth>, }, ChunkedString(Bytes),
}
Expand description

An enum describing the possible data types in RESP3 along with the corresponding Rust data type to represent the payload.

https://github.com/antirez/RESP3/blob/master/spec.md

Variants§

§

BlobString

A binary-safe blob.

Fields

§data: Bytes
§attributes: Option<Attributes>
§

BlobError

A binary-safe blob representing an error.

Fields

§data: Bytes
§attributes: Option<Attributes>
§

SimpleString

A small non binary-safe string.

The internal data type is Bytes in order to support callers that use this interface to parse a MONITOR stream.

Fields

§data: Bytes
§attributes: Option<Attributes>
§

SimpleError

A small non binary-safe string representing an error.

Fields

§data: Str
§attributes: Option<Attributes>
§

Boolean

A boolean type.

Fields

§data: bool
§attributes: Option<Attributes>
§

Null

A null type.

§

Number

A signed 64 bit integer.

Fields

§data: i64
§attributes: Option<Attributes>
§

Double

A signed 64 bit floating point number.

Fields

§data: f64
§attributes: Option<Attributes>
§

BigNumber

A large number not representable as a Number or Double.

This library does not attempt to parse this, nor does it offer any utilities to do so.

Fields

§data: Bytes
§attributes: Option<Attributes>
§

VerbatimString

A binary-safe string to be displayed without any escaping or filtering.

Fields

§data: Bytes
§attributes: Option<Attributes>
§

Array

An array of frames, arbitrarily nested.

Fields

§data: Vec<Frame>
§attributes: Option<Attributes>
§

Map

An unordered map of key-value pairs.

According to the spec keys can be any other RESP3 data type. However, it doesn’t make sense to implement Hash for certain Rust data types like HashMap, Vec, HashSet, etc, so this library limits the possible data types for keys to only those that can be hashed in a semi-sane way.

For example, attempting to create a Frame::Map<HashMap<Frame::Set<HashSet<Frame>>, Frame::Foo>> from bytes will panic.

Fields

§attributes: Option<Attributes>
§

Set

An unordered collection of other frames with a uniqueness constraint.

Fields

§attributes: Option<Attributes>
§

Push

Out-of-band data to be returned to the caller if necessary.

Fields

§data: Vec<Frame>
§attributes: Option<Attributes>
§

Hello

A special frame type used when first connecting to the server to describe the protocol version and optional credentials.

Fields

§version: RespVersion
§auth: Option<Auth>
§

ChunkedString(Bytes)

One chunk of a streaming string.

Implementations§

Source§

impl Frame

Source

pub fn can_hash(&self) -> bool

Whether or not the frame can be used as a key in a HashMap or HashSet.

Not all frame types can be hashed, and trying to do so can panic. This function can be used to handle this gracefully.

Source

pub fn attributes(&self) -> Option<&Attributes>

Read the attributes attached to the frame.

Source

pub fn take_attributes(&mut self) -> Option<Attributes>

Take the attributes off this frame.

Source

pub fn attributes_mut(&mut self) -> Option<&mut Attributes>

Read a mutable reference to any attributes attached to the frame.

Source

pub fn add_attributes( &mut self, attributes: Attributes, ) -> Result<(), RedisProtocolError>

Attempt to add attributes to the frame, extending the existing attributes if needed.

Source

pub fn new_end_stream() -> Self

Create a new Frame that terminates a stream.

Source

pub fn len(&self) -> usize

A context-aware length function that returns the length of the inner frame contents.

This does not return the encoded length, but rather the length of the contents of the frame such as the number of elements in an array, the size of any inner buffers, etc.

Note: Null has a length of 0 and Hello, Number, Double, and Boolean have a length of 1.

See encode_len to read the number of bytes necessary to encode the frame.

Source

pub fn take(&mut self) -> Frame

Replace self with Null, returning the original value.

Source

pub fn kind(&self) -> FrameKind

Read the associated FrameKind.

Source

pub fn is_null(&self) -> bool

Whether or not the frame is a Null variant.

Source

pub fn is_array(&self) -> bool

Whether or not the frame represents an array of frames.

Source

pub fn is_push(&self) -> bool

Whether or not the frame represents data pushed to the client from the server.

Source

pub fn is_boolean(&self) -> bool

Whether or not the frame is a boolean value.

Source

pub fn is_error(&self) -> bool

Whether or not the frame represents an error.

Source

pub fn is_aggregate_type(&self) -> bool

Whether or not the frame is an array, map, or set.

Source

pub fn is_blob(&self) -> bool

Whether or not the frame represents a BlobString or BlobError.

Source

pub fn is_chunked_string(&self) -> bool

Whether or not the frame represents a chunked string.

Source

pub fn is_end_stream_frame(&self) -> bool

Whether or not the frame is an empty chunked string, signifying the end of a chunked string stream.

Source

pub fn is_verbatim_string(&self) -> bool

Whether or not the frame is a verbatim string.

Source

pub fn verbatim_string_format(&self) -> Option<&VerbatimStringFormat>

If the frame is a verbatim string then read the associated format.

Source

pub fn as_str(&self) -> Option<&str>

Read the frame as a string slice if it can be parsed as a UTF-8 string without allocating.

Numbers and Doubles will not be cast to a string since that would require allocating.

Source

pub fn to_string(&self) -> Option<String>

Read the frame as a String if it can be parsed as a UTF-8 string.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

Attempt to read the frame as a byte slice.

Source

pub fn as_i64(&self) -> Option<i64>

Attempt to read the frame as an i64.

Source

pub fn as_f64(&self) -> Option<f64>

Attempt to read the frame as an f64.

Source

pub fn is_moved_or_ask_error(&self) -> bool

Whether or not the frame represents a MOVED or ASK error.

Source

pub fn to_redirection(&self) -> Option<Redirection>

Attempt to parse the frame as a cluster redirection error.

Source

pub fn is_normal_pubsub(&self) -> bool

Whether or not the frame represents a publish-subscribe message, but not a pattern publish-subscribe message.

Source

pub fn is_pubsub_message(&self) -> bool

Whether or not the frame represents a message on a publish-subscribe channel.

Source

pub fn is_pattern_pubsub_message(&self) -> bool

Whether or not the frame represents a message on a publish-subscribe channel matched against a pattern subscription.

Source

pub fn parse_as_pubsub(self) -> Result<(Frame, Frame), Self>

Attempt to parse the frame as a publish-subscribe message, returning the (channel, message) tuple if successful, or the original frame if the inner data is not a publish-subscribe message.

Source

pub fn encode_len(&self) -> Result<usize, RedisProtocolError>

Attempt to read the number of bytes needed to encode the frame.

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Frame

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Frame

Source§

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

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

impl From<bool> for Frame

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Frame

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl Hash for Frame

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Frame

Source§

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

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

const 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 TryFrom<HashMap<Frame, Frame>> for Frame

Source§

type Error = RedisProtocolError

The type returned in the event of a conversion error.
Source§

fn try_from(value: HashMap<Frame, Frame>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<HashSet<Frame>> for Frame

Source§

type Error = RedisProtocolError

The type returned in the event of a conversion error.
Source§

fn try_from(value: HashSet<Frame>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<f64> for Frame

Source§

type Error = RedisProtocolError

The type returned in the event of a conversion error.
Source§

fn try_from(value: f64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

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

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.