2024-01-10 16:43:56 +00:00
|
|
|
use crate::sql::{fmt::Fmt, Table};
|
2023-08-17 18:03:46 +00:00
|
|
|
use revision::revisioned;
|
2020-06-29 15:36:01 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-10-04 21:51:18 +00:00
|
|
|
use std::fmt::{self, Display, Formatter};
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2023-08-18 22:51:56 +00:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
2024-01-09 15:34:52 +00:00
|
|
|
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
2023-08-17 18:03:46 +00:00
|
|
|
#[revisioned(revision = 1)]
|
2020-06-29 15:36:01 +00:00
|
|
|
pub enum Kind {
|
|
|
|
Any,
|
2023-08-27 10:22:27 +00:00
|
|
|
Null,
|
2020-06-29 15:36:01 +00:00
|
|
|
Bool,
|
2023-03-31 22:38:29 +00:00
|
|
|
Bytes,
|
2020-06-29 15:36:01 +00:00
|
|
|
Datetime,
|
2022-04-04 21:43:10 +00:00
|
|
|
Decimal,
|
|
|
|
Duration,
|
|
|
|
Float,
|
|
|
|
Int,
|
2020-06-29 15:36:01 +00:00
|
|
|
Number,
|
|
|
|
Object,
|
2023-04-25 10:13:04 +00:00
|
|
|
Point,
|
2020-06-29 15:36:01 +00:00
|
|
|
String,
|
2023-04-25 10:13:04 +00:00
|
|
|
Uuid,
|
2020-06-29 15:36:01 +00:00
|
|
|
Record(Vec<Table>),
|
2022-04-04 21:43:10 +00:00
|
|
|
Geometry(Vec<String>),
|
2023-04-25 10:13:04 +00:00
|
|
|
Option(Box<Kind>),
|
|
|
|
Either(Vec<Kind>),
|
|
|
|
Set(Box<Kind>, Option<u64>),
|
|
|
|
Array(Box<Kind>, Option<u64>),
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Kind {
|
2022-10-04 21:51:18 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
Self::Any
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 10:13:04 +00:00
|
|
|
impl Kind {
|
|
|
|
fn is_any(&self) -> bool {
|
|
|
|
matches!(self, Kind::Any)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-06 06:12:59 +00:00
|
|
|
impl From<&Kind> for Box<Kind> {
|
|
|
|
#[inline]
|
|
|
|
fn from(v: &Kind) -> Self {
|
|
|
|
Box::new(v.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 21:51:18 +00:00
|
|
|
impl Display for Kind {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
2020-06-29 15:36:01 +00:00
|
|
|
match self {
|
2022-09-27 21:35:30 +00:00
|
|
|
Kind::Any => f.write_str("any"),
|
2023-08-27 10:22:27 +00:00
|
|
|
Kind::Null => f.write_str("null"),
|
2022-09-27 21:35:30 +00:00
|
|
|
Kind::Bool => f.write_str("bool"),
|
2023-03-31 22:38:29 +00:00
|
|
|
Kind::Bytes => f.write_str("bytes"),
|
2022-09-27 21:35:30 +00:00
|
|
|
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"),
|
2023-04-25 10:13:04 +00:00
|
|
|
Kind::Point => f.write_str("point"),
|
2022-09-27 21:35:30 +00:00
|
|
|
Kind::String => f.write_str("string"),
|
2023-04-25 10:13:04 +00:00
|
|
|
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)),
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|