use crate::Session;
pub(crate) trait ProtectedInner<T> {
fn inner(&self) -> T;
}
pub(crate) trait Protected<T>: ProtectedInner<T> {
fn build(inner: T) -> Self;
}
pub(crate) trait ProtectedWithSession<T>: ProtectedInner<T> {
fn build(inner: T, session: Session) -> Self;
fn session(&self) -> &Session;
}
macro_rules! enhance_nullary_enum {
( $this_name:ident, $that_name: ident, {
$( ($this:ident, $that:ident, $name:expr), )*
} $( , omit { $( $not_that:ident ),* } )* ) => {
impl ::std::fmt::Display for $this_name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> {
write!(f, "{}", match *self {
$( $this_name::$this => $name, )*
})
}
}
impl ::std::str::FromStr for $this_name {
type Err = String;
fn from_str(s: &str) -> ::std::result::Result<Self, Self::Err> {
match s {
$( $name => Ok($this_name::$this), )*
_ => Err(format!("Unrecognized {}: {}", stringify!($this_name), s)),
}
}
}
impl $crate::cassandra::util::ProtectedInner<$that_name> for $this_name {
fn inner(&self) -> $that_name {
match *self {
$( $this_name::$this => $that_name::$that ),*
}
}
}
impl $crate::cassandra::util::Protected<$that_name> for $this_name {
fn build(inner: $that_name) -> Self {
match inner {
$( $that_name::$that => $this_name::$this, )*
$($( $that_name::$not_that => panic!(stringify!(Unexpected variant $that_name::$not_that)), )*)*
}
}
}
impl $this_name {
pub fn variants() -> &'static [$this_name] {
static VARIANTS: [ $this_name; 0 $( + ($this_name::$this, 1).1 )* ] =
[ $( $this_name::$this ),* ];
&VARIANTS
}
}
};
}