pub enum Frame {
SimpleString(Bytes),
Error(Bytes),
Integer(i64),
BulkString(Option<Bytes>),
Array(Option<Vec<Frame>>),
}Expand description
A parsed RESP2 frame.
Variants§
SimpleString(Bytes)
Simple string: +OK\r\n
Error(Bytes)
Error: -ERR message\r\n
Integer(i64)
Integer: :42\r\n
BulkString(Option<Bytes>)
Bulk string: $6\r\nfoobar\r\n
Array(Option<Vec<Frame>>)
Array: *N\r\n...
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn as_bytes(&self) -> Option<&Bytes>
pub fn as_bytes(&self) -> Option<&Bytes>
Returns the bytes if this is a SimpleString, Error, or BulkString.
For BulkString(None) (null), returns None.
Sourcepub fn as_str(&self) -> Option<&str>
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.
Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Returns the integer value if this is an Integer frame.
Sourcepub fn as_array(&self) -> Option<&[Frame]>
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.
Sourcepub fn into_array(self) -> Result<Vec<Frame>, Frame>
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.
Sourcepub fn into_bulk_string(self) -> Result<Bytes, Frame>
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.
Trait Implementations§
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> 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
Mutably borrows from an owned value. Read more