1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
extern crate proc_macro;
use TokenStream;
use quote;
use ;
/// Derives the `FromRedisValue` trait for a struct
///
/// This procedural macro allows you to automatically implement the `FromRedisValue` trait
/// for a given struct, enabling seamless deserialization from Redis values. It is particularly
/// useful when working with Redis data stored in JSON format, as it simplifies the process of
/// converting Redis values into Rust structs.
///
/// # Requirements
///
/// Model must implement `serde::Serialize` and `serde::Deserialize`
///
/// # Arguments
///
/// * `input` - The input token stream representing the struct for which the trait is being derived.
///
/// # Returns
///
/// A `TokenStream` containing the implementation of the `FromRedisValue` trait for the specified struct.
///
/// # Examples
///
/// ```rust, no_run
/// // redis-rs, since it reimported in grapple_db, you can use it like this
/// use grapple_db::redis::{self, FromRedisValue};
/// use grapple_redis_macros::FromRedisValue;
/// use serde::{Deserialize, Serialize};
///
/// #[derive(Debug, Deserialize, Serialize, FromRedisValue)]
/// struct MyStruct {
/// field1: String,
/// field2: i32,
/// }
///
/// fn example(redis_value: &redis::Value) -> Result<MyStruct, redis::RedisError> {
/// MyStruct::from_redis_value(redis_value)
/// }
/// ```