Expand description
§serde-RESP
Redis RESP protocol serialization and deserialization with serde. Read Specification
§Usage
IMPORTANT: Do NOT (de)serialize with any other types besides RESP/RESPType! You may get panic or incorrect results!
Why?
Here are the RESP types and their corresponding Rust types for (de)serialize operations.
Simple StringErrorIntegerBulk String- RESP::BulkString(Option<Vec
>) - Use
Nonefor null bulk strings andSomefor non-null ones.
- Use
- RESP::BulkString(Option<Vec
Array- RESP::Array(Option<Vec
>) - Use
Nonefor null arrays andSomefor non-null ones.
- Use
- RESP::Array(Option<Vec
To serialize, use ser::to_string or ser::to_writer.
To deserialize, use de::from_str or de::from_reader or de::from_buf_reader.
For usage examples, refer to RESP
§Macros
Since 0.3.0, you can start using very handy macros! Here is a demo:
use serde_resp::{array, array_null, bulk, bulk_null, de, err_str, int, ser, simple, RESP};
let resp_array = array![
simple!("simple string".to_owned()),
err_str!("error string".to_owned()),
int!(42),
bulk!(b"bulk string".to_vec()),
bulk_null!(),
array![
simple!("arrays of arrays!".to_owned()),
array![simple!("OK ENOUGH!".to_owned())],
],
array_null!(),
];
let serialized = ser::to_string(&resp_array).unwrap();
assert_eq!(
"*7\r\n+simple string\r\n-error string\r\n:42\r\n$11\r\nbulk string\r\n$-1\r\n*2\r\n+arrays of arrays!\r\n*1\r\n+OK ENOUGH!\r\n*-1\r\n",
serialized
);
let deserialized = de::from_str(&serialized).unwrap();
assert_eq!(resp_array, deserialized);Modules§
Macros§
- array
array![...]is equivalent toRESP::Array(Some(vec![...])).- array_
null array_null!()is equivalent toRESP::Array(None).- bulk
bulk!(...)is equivalent toRESP::BulkString(Some(...)).- bulk_
null bulk_null!()is equivalent toRESP::BulkString(None).- err_str
err_str!(...)is equivalent toRESP::Error(...).- int
int!(...)is equivalent toRESP::Integer(...).- simple
simple!(...)is equivalent toRESP::SimpleString(...).
Enums§
- Error
- Error type used by the crate.
- RESP
Type - This enum creates a one-to-one type mapping with RESP types. Please only use variants of this type for (de)serialize operations.