#![cfg_attr(not(feature = "bench"), warn(missing_docs))]
#![warn(missing_debug_implementations)]
#![deny(unsafe_code)]
#![allow(clippy::needless_doctest_main)]
#[cfg(all(feature = "runtime_tokio", feature = "runtime_async_std"))]
compile_error!("The `runtime_tokio` and `runtime_async_std` features are mutually exclusive!");
#[cfg(not(any(feature = "runtime_tokio", feature = "runtime_async_std")))]
compile_error!("Expected one of the features `runtime_tokio` or `runtime_async_std`");
#[macro_use]
extern crate quick_error;
mod command;
mod connection;
mod connectionpool;
mod error;
#[cfg(feature = "runtime_async_std")]
pub use async_std::net::ToSocketAddrs;
#[cfg(feature = "runtime_tokio")]
pub use tokio::net::ToSocketAddrs;
#[cfg(feature = "bench")]
pub mod test;
#[cfg(all(not(feature = "bench"), test))]
mod test;
pub use command::{Command, CommandList};
pub use connection::{
builder::MSetBuilder, Connection, HScanBuilder, HScanStream, Message, MessageStream, PMessage,
PMessageStream, ResponseStream, ScanBuilder, ScanStream,
};
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 unwrap_bool(self) -> bool {
self.unwrap_integer() != 0
}
#[inline]
pub fn unwrap_string_array(self) -> Vec<Vec<u8>> {
self.unwrap_array()
.into_iter()
.map(|v| v.unwrap_string())
.collect()
}
#[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,
}
}
#[inline]
pub fn optional_bool(self) -> Option<bool> {
self.optional_integer().map(|i| i != 0)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum DataType {
String,
List,
Set,
ZSet,
Hash,
Stream,
}