macro_rules! redis_value {
({$($k:tt: $v:tt),* $(,)*}) => { ... };
([$($e:tt),* $(,)*]) => { ... };
(set:[$($e:tt),* $(,)*]) => { ... };
(simple:$e:tt) => { ... };
(nil) => { ... };
(ok) => { ... };
(okay) => { ... };
(($context:tt:$e:tt)) => { ... };
($e:expr) => { ... };
}Expand description
Build Values from a JSON-like notation
This macro handles:
u8,u16,u32,i8,i16,i32,i64,String,&strand other types that implementIntoRedisValuetrue,false- map to their correspondingValue::Booleannil- maps toValue::Nilok,okay- map toValue::Okay[element1, element2, ..., elementN]- maps toValue::Array{key1: value1, key2: value2, ..., keyN: valueN]- maps toValue::Mapset:[element1, element2, ..., elementN]- maps toValue::Set(wrap in()within complex structures)simple:"SomeString"- maps toValue::SimpleString(wrap in()within complex structures)
ยงExample
use redis::Value;
use redis_test::redis_value;
let actual = redis_value!([42, "foo", {true: nil}]);
let expected = Value::Array(vec![
Value::Int(42),
Value::BulkString("foo".as_bytes().to_vec()),
Value::Map(vec![(Value::Boolean(true), Value::Nil)])
]);
assert_eq!(actual, expected)