Derive Macro redis_args_impl::ToRedisArgs

source ·
#[derive(ToRedisArgs)]
{
    // Attributes available to this derive:
    #[to_redis_args]
}
Expand description

Can be derived by structs or enums in order to allow conversion to redis args.

This can be used in different variants, either using a format string or the serde serialization.

§Format string

The format string is limited to plain {name} arguments, no extra formatting allowed. This restriction is currently necessary, because detecting which fields should be formatted would be significantly more difficult otherwise.

This variant can only be used with structs, either named or anonymous.

§Examples

§Struct with named fields

#[derive(ToRedisArgs)]
#[to_redis_args(fmt = "path:to:id={id}:with:value:{value}")]
struct IdValue {
   id: String,
   value: u32,
   count: usize,
}

§Struct with unnamed fields

#[derive(ToRedisArgs)]
#[to_redis_args(fmt = "path:to:{0}:with:{1}")]
struct Example(u32, String);

§Serde

Serializes to JSON using the serde serialization of any item. The item must derive serde::Serialize.

§Examples

#[derive(ToRedisArgs, Serialize)]
#[to_redis_args(serde)]
struct IdValue {
    id: String,
    value: u32,
    count: usize,
}