use std::convert::TryFrom;
use std::fmt;
pub use self::client::Client;
use crate::Error;
mod client;
pub mod lowering;
mod requests;
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub enum ColumnFamily {
Default,
Lock,
Write,
}
impl TryFrom<&str> for ColumnFamily {
type Error = Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"default" => Ok(ColumnFamily::Default),
"lock" => Ok(ColumnFamily::Lock),
"write" => Ok(ColumnFamily::Write),
s => Err(Error::ColumnFamilyError(s.to_owned())),
}
}
}
impl TryFrom<String> for ColumnFamily {
type Error = Error;
fn try_from(value: String) -> Result<Self, Self::Error> {
TryFrom::try_from(&*value)
}
}
impl fmt::Display for ColumnFamily {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ColumnFamily::Default => f.write_str("default"),
ColumnFamily::Lock => f.write_str("lock"),
ColumnFamily::Write => f.write_str("write"),
}
}
}
trait RawRpcRequest: Default {
fn set_cf(&mut self, cf: String);
fn maybe_set_cf(&mut self, cf: Option<ColumnFamily>) {
if let Some(cf) = cf {
self.set_cf(cf.to_string());
}
}
}