use crate::sql::{fmt::Fmt, Table};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[revisioned(revision = 1)]
pub enum Kind {
Any,
Null,
Bool,
Bytes,
Datetime,
Decimal,
Duration,
Float,
Int,
Number,
Object,
Point,
String,
Uuid,
Record(Vec
),
Geometry(Vec),
Option(Box),
Either(Vec),
Set(Box, Option),
Array(Box, Option),
}
impl Default for Kind {
fn default() -> Self {
Self::Any
}
}
impl Kind {
fn is_any(&self) -> bool {
matches!(self, Kind::Any)
}
}
impl From<&Kind> for Box {
#[inline]
fn from(v: &Kind) -> Self {
Box::new(v.clone())
}
}
impl Display for Kind {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Kind::Any => f.write_str("any"),
Kind::Null => f.write_str("null"),
Kind::Bool => f.write_str("bool"),
Kind::Bytes => f.write_str("bytes"),
Kind::Datetime => f.write_str("datetime"),
Kind::Decimal => f.write_str("decimal"),
Kind::Duration => f.write_str("duration"),
Kind::Float => f.write_str("float"),
Kind::Int => f.write_str("int"),
Kind::Number => f.write_str("number"),
Kind::Object => f.write_str("object"),
Kind::Point => f.write_str("point"),
Kind::String => f.write_str("string"),
Kind::Uuid => f.write_str("uuid"),
Kind::Option(k) => write!(f, "option<{}>", k),
Kind::Record(k) => match k {
k if k.is_empty() => write!(f, "record"),
k => write!(f, "record<{}>", Fmt::verbar_separated(k)),
},
Kind::Geometry(k) => match k {
k if k.is_empty() => write!(f, "geometry"),
k => write!(f, "geometry<{}>", Fmt::verbar_separated(k)),
},
Kind::Set(k, l) => match (k, l) {
(k, None) if k.is_any() => write!(f, "set"),
(k, None) => write!(f, "set<{k}>"),
(k, Some(l)) => write!(f, "set<{k}, {l}>"),
},
Kind::Array(k, l) => match (k, l) {
(k, None) if k.is_any() => write!(f, "array"),
(k, None) => write!(f, "array<{k}>"),
(k, Some(l)) => write!(f, "array<{k}, {l}>"),
},
Kind::Either(k) => write!(f, "{}", Fmt::verbar_separated(k)),
}
}
}