1#[cfg(test)]
7#[path = "./types_test.rs"]
8mod types_test;
9
10use std::error::Error;
11use std::fmt;
12use std::fmt::Display;
13
14#[derive(Debug)]
15pub enum RedisError {
17 RedisError(redis::RedisError),
19 Description(&'static str),
21}
22
23impl Display for RedisError {
24 fn fmt(&self, format: &mut fmt::Formatter) -> Result<(), fmt::Error> {
26 match self {
27 Self::RedisError(ref cause) => cause.fmt(format),
28 Self::Description(description) => description.fmt(format),
29 }
30 }
31}
32
33impl Error for RedisError {
34 fn source(&self) -> Option<&(dyn Error + 'static)> {
35 match self {
36 Self::RedisError(error) => Some(error),
37 Self::Description(_) => None,
38 }
39 }
40}
41
42pub trait RedisArg: Sized + ToString {}
44
45macro_rules! as_redis_arg {
46 ($t:ty) => {
47 impl RedisArg for $t {}
48 };
49}
50
51impl<'a> RedisArg for &'a str {}
52
53as_redis_arg!(u8);
54as_redis_arg!(i8);
55as_redis_arg!(i16);
56as_redis_arg!(u16);
57as_redis_arg!(i32);
58as_redis_arg!(u32);
59as_redis_arg!(i64);
60as_redis_arg!(u64);
61as_redis_arg!(i128);
62as_redis_arg!(u128);
63as_redis_arg!(f32);
64as_redis_arg!(f64);
65as_redis_arg!(isize);
66as_redis_arg!(usize);
67as_redis_arg!(bool);
68
69pub type Message = redis::Msg;
71
72pub type RedisResult<T> = Result<T, RedisError>;
74
75pub type RedisEmptyResult = RedisResult<()>;
77
78pub type RedisStringResult = RedisResult<String>;
80
81pub type RedisBoolResult = RedisResult<bool>;
83
84#[derive(Debug, Clone, Copy, Default)]
85pub struct Interrupts {
87 pub stop: bool,
89 pub next_polling_time: Option<u64>,
91}
92
93impl Interrupts {
94 pub fn new() -> Interrupts {
96 Default::default()
97 }
98}