Skip to main content

Frame

Enum Frame 

Source
pub enum Frame {
Show 32 variants SimpleString(Bytes), Error(Bytes), Integer(i64), BulkString(Option<Bytes>), BlobError(Bytes), StreamedStringHeader, StreamedBlobErrorHeader, StreamedVerbatimStringHeader, StreamedArrayHeader, StreamedSetHeader, StreamedMapHeader, StreamedAttributeHeader, StreamedPushHeader, StreamedStringChunk(Bytes), StreamedString(Vec<Bytes>), StreamedArray(Vec<Frame>), StreamedSet(Vec<Frame>), StreamedMap(Vec<(Frame, Frame)>), StreamedAttribute(Vec<(Frame, Frame)>), StreamedPush(Vec<Frame>), StreamTerminator, Null, Double(f64), SpecialFloat(Bytes), Boolean(bool), BigNumber(Bytes), VerbatimString(Bytes, Bytes), Array(Option<Vec<Frame>>), Set(Vec<Frame>), Map(Vec<(Frame, Frame)>), Attribute(Vec<(Frame, Frame)>), Push(Vec<Frame>),
}
Expand description

A parsed RESP3 frame.

Each variant corresponds to one of the RESP3 types, including both fixed-length and streaming headers for bulk strings, arrays, sets, maps, attributes, and pushes.

Variants§

§

SimpleString(Bytes)

Simple string: +<string>\r\n

§

Error(Bytes)

Simple error: -<error>\r\n

§

Integer(i64)

Integer: :<number>\r\n

§

BulkString(Option<Bytes>)

Blob string: $<length>\r\n<bytes>\r\n

§

BlobError(Bytes)

Blob error: !<length>\r\n<bytes>\r\n

§

StreamedStringHeader

Streaming blob string header: $?\r\n

§

StreamedBlobErrorHeader

Streaming blob error header: !?\r\n

§

StreamedVerbatimStringHeader

Streaming verbatim string header: =?\r\n

§

StreamedArrayHeader

Streaming array header: *?\r\n

§

StreamedSetHeader

Streaming set header: ~?\r\n

§

StreamedMapHeader

Streaming map header: %?\r\n

§

StreamedAttributeHeader

Streaming attribute header: |?\r\n

§

StreamedPushHeader

Streaming push header: >?\r\n

§

StreamedStringChunk(Bytes)

Streaming string chunk: ;length\r\ndata\r\n

Represents an individual chunk in a streaming string sequence. These chunks are parsed from ;{length}\r\n{data}\r\n format. A zero-length chunk (;0\r\n) indicates the end of the stream.

§Example

use resp_rs::resp3::Frame;
use bytes::Bytes;

// Chunk containing "Hello"
// Wire format: ;5\r\nHello\r\n
Frame::StreamedStringChunk(Bytes::from("Hello"));
§

StreamedString(Vec<Bytes>)

Accumulated streaming string data from multiple chunks

Created by parse_streaming_sequence() when parsing a complete streaming string sequence ($?\r\n + chunks + ;0\r\n). Contains all chunks in order, allowing reconstruction of the full string.

§Example

use resp_rs::resp3::Frame;
use bytes::Bytes;

// Represents "Hello world" from chunks ["Hello ", "world"]
Frame::StreamedString(vec![
    Bytes::from("Hello "),
    Bytes::from("world")
]);
§

StreamedArray(Vec<Frame>)

Accumulated streaming array data from multiple chunks

Created when parsing a streaming array sequence (*?\r\n + frames + .\r\n). Contains all frames that were streamed as part of the array.

§Example

use resp_rs::resp3::Frame;
use bytes::Bytes;

// Array with mixed types
Frame::StreamedArray(vec![
    Frame::SimpleString(Bytes::from("hello")),
    Frame::Integer(42),
    Frame::Boolean(true)
]);
§

StreamedSet(Vec<Frame>)

Accumulated streaming set data from multiple chunks

Created when parsing a streaming set sequence (~?\r\n + frames + .\r\n). Contains all unique elements that were streamed as part of the set.

§

StreamedMap(Vec<(Frame, Frame)>)

Accumulated streaming map data from multiple chunks

Created when parsing a streaming map sequence (%?\r\n + key-value pairs + .\r\n). Contains all key-value pairs that were streamed as part of the map.

§Example

use resp_rs::resp3::Frame;
use bytes::Bytes;

Frame::StreamedMap(vec![
    (Frame::SimpleString(Bytes::from("name")), Frame::SimpleString(Bytes::from("Alice"))),
    (Frame::SimpleString(Bytes::from("age")), Frame::Integer(25))
]);
§

StreamedAttribute(Vec<(Frame, Frame)>)

Accumulated streaming attribute data from multiple chunks

Created when parsing a streaming attribute sequence (|?\r\n + key-value pairs + .\r\n). Attributes provide out-of-band metadata that doesn’t affect the main data structure.

§

StreamedPush(Vec<Frame>)

Accumulated streaming push data from multiple chunks

Created when parsing a streaming push sequence (>?\r\n + frames + .\r\n). Push messages are server-initiated communications (e.g., pub/sub messages).

§Example

use resp_rs::resp3::Frame;
use bytes::Bytes;

// Pub/sub message
Frame::StreamedPush(vec![
    Frame::SimpleString(Bytes::from("pubsub")),
    Frame::SimpleString(Bytes::from("channel1")),
    Frame::SimpleString(Bytes::from("message content"))
]);
§

StreamTerminator

End-of-stream terminator for all chunked sequences: .\r\n

§

Null

Null: _\r\n

§

Double(f64)

Double: ,<float>\r\n

§

SpecialFloat(Bytes)

Special Float: ,inf\r\n, -inf\r\n, nan\r\n

§

Boolean(bool)

Boolean: #t\r\n or #f\r\n

§

BigNumber(Bytes)

Big number: (<number>\r\n

§

VerbatimString(Bytes, Bytes)

Verbatim string: =format:content\r\n

§

Array(Option<Vec<Frame>>)

Array: *<count>\r\n… (or streaming header *?\r\n)

§

Set(Vec<Frame>)

Set: ~<count>\r\n… (or streaming header ~?\r\n)

§

Map(Vec<(Frame, Frame)>)

Map: %<count>\r\n… (or streaming header %?\r\n)

§

Attribute(Vec<(Frame, Frame)>)

Attribute: |<count>\r\n… (or streaming header |?\r\n)

§

Push(Vec<Frame>)

Push: > <count>\r\n… (or streaming header >?\r\n)

Implementations§

Source§

impl Frame

Source

pub fn as_bytes(&self) -> Option<&Bytes>

Returns the bytes if this is a string-like frame (SimpleString, Error, BulkString, BlobError, or BigNumber).

For BulkString(None) (null), returns None.

Source

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

Returns the string data as a UTF-8 &str, if this is a string-like frame and contains valid UTF-8.

Source

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

Returns the integer value if this is an Integer frame.

Source

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

Returns the double value if this is a Double frame.

Source

pub fn as_boolean(&self) -> Option<bool>

Returns the boolean value if this is a Boolean frame.

Source

pub fn as_array(&self) -> Option<&[Frame]>

Returns a reference to the array items if this is an Array.

For Array(None) (null), returns None.

Source

pub fn as_set(&self) -> Option<&[Frame]>

Returns a reference to the set items if this is a Set.

Source

pub fn as_map(&self) -> Option<&[(Frame, Frame)]>

Returns a reference to the map pairs if this is a Map.

Source

pub fn as_push(&self) -> Option<&[Frame]>

Returns a reference to the push items if this is a Push.

Source

pub fn as_verbatim_string(&self) -> Option<(&Bytes, &Bytes)>

Returns the verbatim string format and content if this is a VerbatimString.

Source

pub fn into_array(self) -> Result<Vec<Frame>, Frame>

Consumes the frame and returns the array items.

Returns Err(self) if this is not a non-null Array.

Source

pub fn into_bulk_string(self) -> Result<Bytes, Frame>

Consumes the frame and returns the bulk string bytes.

Returns Err(self) if this is not a non-null BulkString.

Source

pub fn into_map(self) -> Result<Vec<(Frame, Frame)>, Frame>

Consumes the frame and returns the map pairs.

Returns Err(self) if this is not a Map.

Source

pub fn into_set(self) -> Result<Vec<Frame>, Frame>

Consumes the frame and returns the set items.

Returns Err(self) if this is not a Set.

Source

pub fn is_null(&self) -> bool

Returns true if this is Null or a null bulk string/array.

Source

pub fn is_error(&self) -> bool

Returns true if this is an Error or BlobError 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§

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