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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#![feature(async_await)]
#![deny(missing_docs)]
#[macro_use]
extern crate quick_error;
mod command;
mod connection;
mod connectionpool;
mod error;
#[cfg(test)]
mod test;
pub use command::{Command, CommandList};
pub use connection::Connection;
pub use connectionpool::ConnectionPool;
pub use error::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, PartialEq)]
pub enum Value {
Ok,
Nil,
Array(Vec<Value>),
Integer(isize),
String(Vec<u8>),
}
impl Value {
#[inline]
pub fn unwrap_integer(self) -> isize {
if let Value::Integer(i) = self {
i
} else {
panic!("expected integer value, got {:?}", self)
}
}
#[inline]
pub fn unwrap_array(self) -> Vec<Value> {
if let Value::Array(a) = self {
a
} else {
panic!("expected array value, got {:?}", self)
}
}
#[inline]
pub fn unwrap_string(self) -> Vec<u8> {
if let Value::String(s) = self {
s
} else {
panic!("expected string value, got {:?}", self)
}
}
#[inline]
pub fn optional_string(self) -> Option<Vec<u8>> {
match self {
Value::String(s) => Some(s),
_ => None,
}
}
#[inline]
pub fn optional_array(self) -> Option<Vec<Value>> {
match self {
Value::Array(a) => Some(a),
_ => None,
}
}
#[inline]
pub fn optional_integer(self) -> Option<isize> {
match self {
Value::Integer(i) => Some(i),
_ => None,
}
}
}