Skip to main content

Reply

Enum Reply 

Source
pub enum Reply {
Show 15 variants Simple(Vec<u8>), Error(Vec<u8>), Int(i64), Bulk(Vec<u8>), Nil, Array(Vec<Reply>), Map(Vec<(Reply, Reply)>), Set(Vec<Reply>), Double(f64), Boolean(bool), Verbatim { fmt: [u8; 3], data: Vec<u8>, }, BigNumber(Vec<u8>), Null, Push(Vec<Reply>), BlobError(Vec<u8>),
}
Expand description

A parsed RESP reply (server → client) — the client-side counterpart of the crate’s encode_* functions (server-side encoders).

Variants prefixed with Resp3: in their doc are only ever produced by a server speaking RESP3; an HELLO 2 (or no HELLO) session sees the RESP2 subset (Simple / Error / Int / Bulk / Nil / Array) exclusively. The variant set is RESP3’s type set and deliberately exhaustive: a match on Reply lists every wire type, so a decoder cannot silently drop one.

use kevy_resp::{Reply, parse_reply};

let (reply, used) = parse_reply(b"*2\r\n$3\r\nfoo\r\n:7\r\n")?.expect("complete frame");
assert_eq!(used, 17);
match reply {
    Reply::Array(items) => assert_eq!(items, [Reply::Bulk(b"foo".to_vec()), Reply::Int(7)]),
    other => panic!("unexpected {other:?}"),
}

Variants§

§

Simple(Vec<u8>)

+OK

use kevy_resp::{Reply, parse_reply};
assert_eq!(parse_reply(b"+OK\r\n")?, Some((Reply::Simple(b"OK".to_vec()), 5)));
§

Error(Vec<u8>)

-ERR ...

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"-ERR no such key\r\n")?.expect("complete frame");
assert_eq!(reply, Reply::Error(b"ERR no such key".to_vec()));
§

Int(i64)

:42

use kevy_resp::{Reply, parse_reply};
assert_eq!(parse_reply(b":-3\r\n")?, Some((Reply::Int(-3), 5)));
§

Bulk(Vec<u8>)

$5\r\nhello\r\n

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"$5\r\nhello\r\n")?.expect("complete frame");
assert_eq!(reply, Reply::Bulk(b"hello".to_vec()));
§

Nil

$-1 or *-1 — the RESP2 null sentinel; in RESP3 the dedicated Reply::Null (_\r\n) is used instead. Both round-trip here.

use kevy_resp::{Reply, parse_reply};
assert_eq!(parse_reply(b"$-1\r\n")?, Some((Reply::Nil, 5)));
assert_eq!(parse_reply(b"*-1\r\n")?, Some((Reply::Nil, 5)));
§

Array(Vec<Reply>)

*N ...

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"*2\r\n:1\r\n+x\r\n")?.expect("complete frame");
assert_eq!(reply, Reply::Array(vec![Reply::Int(1), Reply::Simple(b"x".to_vec())]));
§

Map(Vec<(Reply, Reply)>)

Resp3: %N\r\n<key1><value1>...<keyN><valueN> — N pairs (the header count is the pair count, NOT the element count, so a map of 3 pairs is %3 plus 6 sub-replies). Parsed/exposed as a Vec of pairs so duplicate keys + insertion order are preserved.

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"%1\r\n+f\r\n:1\r\n")?.expect("complete frame");
assert_eq!(reply, Reply::Map(vec![(Reply::Simple(b"f".to_vec()), Reply::Int(1))]));
§

Set(Vec<Reply>)

Resp3: ~N\r\n<item1>...<itemN> — set semantics on the wire; dedup is the application’s job (RESP3 doesn’t require it).

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"~2\r\n:1\r\n:1\r\n")?.expect("complete frame");
// duplicates reach the caller as sent
assert_eq!(reply, Reply::Set(vec![Reply::Int(1), Reply::Int(1)]));
§

Double(f64)

Resp3: ,1.5\r\n — double. inf / -inf / nan are valid payloads per the RESP3 spec and survive the round-trip.

use kevy_resp::{Reply, parse_reply};
assert_eq!(parse_reply(b",1.5\r\n")?, Some((Reply::Double(1.5), 6)));
let (inf, _) = parse_reply(b",inf\r\n")?.expect("complete frame");
assert_eq!(inf, Reply::Double(f64::INFINITY));
§

Boolean(bool)

Resp3: #t\r\n / #f\r\n — boolean.

use kevy_resp::{Reply, parse_reply};
assert_eq!(parse_reply(b"#t\r\n")?, Some((Reply::Boolean(true), 4)));
§

Verbatim

Resp3: =15\r\ntxt:Some bytes\r\n — verbatim string carrying a 3-char format tag (txt / mkd / etc.) + raw bytes. The colon separator is part of the wire encoding but not part of data.

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"=9\r\ntxt:hello\r\n")?.expect("complete frame");
assert_eq!(reply, Reply::Verbatim { fmt: *b"txt", data: b"hello".to_vec() });

Fields

§fmt: [u8; 3]

3-char format tag (e.g. b"txt" for plain text, b"mkd" for markdown).

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"=8\r\nmkd:# hi\r\n")?.expect("complete frame");
let Reply::Verbatim { fmt, .. } = reply else { panic!("not verbatim") };
assert_eq!(&fmt, b"mkd");
§data: Vec<u8>

Payload bytes following the : separator.

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"=6\r\ntxt:ab\r\n")?.expect("complete frame");
let Reply::Verbatim { data, .. } = reply else { panic!("not verbatim") };
assert_eq!(data, b"ab");
§

BigNumber(Vec<u8>)

Resp3: (170141183460469231731687303715884105727\r\n — arbitrary- precision integer; carried as the raw digit bytes since we don’t pull in a bignum crate (charter: zero deps).

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"(12345678901234567890123\r\n")?.expect("complete frame");
assert_eq!(reply, Reply::BigNumber(b"12345678901234567890123".to_vec()));
§

Null

Resp3: _\r\n — true null. RESP2 falls back to Reply::Nil.

use kevy_resp::{Reply, parse_reply};
assert_eq!(parse_reply(b"_\r\n")?, Some((Reply::Null, 3)));
§

Push(Vec<Reply>)

Resp3: >N\r\n... — like Reply::Array but tagged as an out-of-band server-push frame (pub/sub messages in RESP3). The client must dispatch these separately from regular replies.

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b">2\r\n+message\r\n+hi\r\n")?.expect("complete frame");
assert!(matches!(reply, Reply::Push(ref parts) if parts.len() == 2));
§

BlobError(Vec<u8>)

Resp3: !8\r\nERR ohno\r\n — error carried as a length-prefixed bulk (handles errors containing CRLF that the simple-string - shape can’t encode).

use kevy_resp::{Reply, parse_reply};
let (reply, _) = parse_reply(b"!8\r\nERR ohno\r\n")?.expect("complete frame");
assert_eq!(reply, Reply::BlobError(b"ERR ohno".to_vec()));

Trait Implementations§

Source§

impl Clone for Reply

Source§

fn clone(&self) -> Reply

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Reply

Source§

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

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

impl PartialEq for Reply

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Reply

Auto Trait Implementations§

§

impl Freeze for Reply

§

impl RefUnwindSafe for Reply

§

impl Send for Reply

§

impl Sync for Reply

§

impl Unpin for Reply

§

impl UnsafeUnpin for Reply

§

impl UnwindSafe for Reply

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.