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.
Variants§
BlobString
A binary-safe blob.
BlobError
A binary-safe blob representing an error.
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.
SimpleError
A small non binary-safe string representing an error.
Boolean
A boolean type.
Null
A null type.
Number
A signed 64 bit integer.
Double
A signed 64 bit floating point number.
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.
VerbatimString
A binary-safe string to be displayed without any escaping or filtering.
Array
An array of frames, arbitrarily nested.
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.
Set
An unordered collection of other frames with a uniqueness constraint.
Push
Out-of-band data to be returned to the caller if necessary.
Hello
A special frame type used when first connecting to the server to describe the protocol version and optional credentials.
ChunkedString(Bytes)
One chunk of a streaming string.
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn can_hash(&self) -> bool
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.
Sourcepub fn attributes(&self) -> Option<&Attributes>
pub fn attributes(&self) -> Option<&Attributes>
Read the attributes attached to the frame.
Sourcepub fn take_attributes(&mut self) -> Option<Attributes>
pub fn take_attributes(&mut self) -> Option<Attributes>
Take the attributes off this frame.
Sourcepub fn attributes_mut(&mut self) -> Option<&mut Attributes>
pub fn attributes_mut(&mut self) -> Option<&mut Attributes>
Read a mutable reference to any attributes attached to the frame.
Sourcepub fn add_attributes(
&mut self,
attributes: Attributes,
) -> Result<(), RedisProtocolError>
pub fn add_attributes( &mut self, attributes: Attributes, ) -> Result<(), RedisProtocolError>
Attempt to add attributes to the frame, extending the existing attributes if needed.
Sourcepub fn new_end_stream() -> Self
pub fn new_end_stream() -> Self
Create a new Frame
that terminates a stream.
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn is_push(&self) -> bool
pub fn is_push(&self) -> bool
Whether or not the frame represents data pushed to the client from the server.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Whether or not the frame is a boolean value.
Sourcepub fn is_aggregate_type(&self) -> bool
pub fn is_aggregate_type(&self) -> bool
Whether or not the frame is an array, map, or set.
Sourcepub fn is_chunked_string(&self) -> bool
pub fn is_chunked_string(&self) -> bool
Whether or not the frame represents a chunked string.
Sourcepub fn is_end_stream_frame(&self) -> bool
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.
Sourcepub fn is_verbatim_string(&self) -> bool
pub fn is_verbatim_string(&self) -> bool
Whether or not the frame is a verbatim string.
Sourcepub fn verbatim_string_format(&self) -> Option<&VerbatimStringFormat>
pub fn verbatim_string_format(&self) -> Option<&VerbatimStringFormat>
If the frame is a verbatim string then read the associated format.
Sourcepub fn as_str(&self) -> Option<&str>
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.
Sourcepub fn to_string(&self) -> Option<String>
pub fn to_string(&self) -> Option<String>
Read the frame as a String
if it can be parsed as a UTF-8 string.
Sourcepub fn is_moved_or_ask_error(&self) -> bool
pub fn is_moved_or_ask_error(&self) -> bool
Whether or not the frame represents a MOVED or ASK error.
Sourcepub fn to_redirection(&self) -> Option<Redirection>
pub fn to_redirection(&self) -> Option<Redirection>
Attempt to parse the frame as a cluster redirection error.
Sourcepub fn is_normal_pubsub(&self) -> bool
pub fn is_normal_pubsub(&self) -> bool
Whether or not the frame represents a publish-subscribe message, but not a pattern publish-subscribe message.
Sourcepub fn is_pubsub_message(&self) -> bool
pub fn is_pubsub_message(&self) -> bool
Whether or not the frame represents a message on a publish-subscribe channel.
Sourcepub fn is_pattern_pubsub_message(&self) -> bool
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.
Sourcepub fn parse_as_pubsub(self) -> Result<(Frame, Frame), Self>
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.
Sourcepub fn encode_len(&self) -> Result<usize, RedisProtocolError>
pub fn encode_len(&self) -> Result<usize, RedisProtocolError>
Attempt to read the number of bytes needed to encode the frame.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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