#![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,
}
}
}