use super::named_type::NamedShape;
pub type ShapeFn = fn() -> Shape;
#[derive(Debug, Clone)]
pub enum Shape {
Any,
Bool,
Int {
min: i64,
max: i64,
},
Float {
bits: u32,
},
Str,
Atom,
Bytes,
Ref {
kinds: &'static [&'static str],
id: ShapeFn,
},
Named(NamedShape),
List(ShapeFn),
Map(ShapeFn),
Optional(ShapeFn),
Struct(StructShape),
Enum(EnumShape),
}
#[derive(Debug, Clone)]
pub struct StructShape {
pub name: &'static str,
pub doc: &'static str,
pub fields: Vec<Field>,
}
#[derive(Debug, Clone)]
pub struct Field {
pub name: &'static str,
pub doc: &'static str,
pub shape: ShapeFn,
pub required: bool,
pub range: Option<(f64, f64)>,
}
#[derive(Debug, Clone)]
pub struct EnumShape {
pub name: &'static str,
pub doc: &'static str,
pub tag: Option<&'static str>,
pub variants: Vec<Variant>,
}
#[derive(Debug, Clone)]
pub struct Variant {
pub name: &'static str,
pub doc: &'static str,
pub fields: Vec<Field>,
}
impl Shape {
#[must_use]
pub fn named<T: super::NamedType>() -> Shape {
Shape::Named(NamedShape::of::<T>())
}
#[must_use]
pub fn describe(&self) -> super::ShapeDoc {
super::ShapeDoc::of(self)
}
}