use surrealdb_kvs::release::Release;
#[derive(Clone, Copy, Debug)]
pub struct TypeSchema {
pub name: &'static str,
pub since: Release,
pub reserved: &'static [u32],
pub embedded_in_revision: bool,
pub floor_fixed: bool,
pub shape: Shape,
}
#[derive(Clone, Copy, Debug)]
pub enum Shape {
Struct(&'static [FieldSchema]),
Enum(&'static [VariantSchema]),
Transparent(fn(&mut String)),
}
#[derive(Clone, Copy, Debug)]
pub struct FieldSchema {
pub n: u32,
pub name: &'static str,
pub ty: fn(&mut String),
pub class: Class,
pub since: Release,
pub absent: Absent,
pub supersedes: Option<u32>,
pub independent: Option<&'static str>,
pub unrevisioned: bool,
}
impl FieldSchema {
pub fn type_name(&self) -> String {
let mut out = String::new();
(self.ty)(&mut out);
out
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Class {
Critical,
Ignorable,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Absent {
Required,
None,
Default(&'static str),
}
#[derive(Clone, Copy, Debug)]
pub struct VariantSchema {
pub n: Option<u32>,
pub name: &'static str,
pub since: Release,
pub payload: Payload,
}
#[derive(Clone, Copy, Debug)]
pub enum Payload {
Unit,
Item(fn(&mut String)),
Positional(&'static [fn(&mut String)]),
Fields(&'static [FieldSchema]),
}