#[derive(Debug, Clone, Copy)]
pub enum TypeInfo {
Native(NativeTypeInfo),
Defined(DefinedTypeInfo),
}
#[derive(Debug, Clone, Copy)]
pub struct NativeTypeInfo {
pub r#ref: TypeExpr,
}
#[derive(Debug, Clone, Copy)]
pub struct DefinedTypeInfo {
pub def: TypeDefinition,
pub generic_args: List<TypeExpr>,
}
#[derive(Debug, Clone, Copy)]
pub struct TypeDefinition {
pub docs: Option<Docs>,
pub path: List<Ident>,
pub name: Ident,
pub generic_vars: List<Ident>,
pub def: TypeExpr,
}
#[derive(Debug, Clone, Copy)]
pub enum TypeExpr {
Ref(&'static TypeInfo),
Name(TypeName),
String(TypeString),
Tuple(TypeTuple),
Object(TypeObject),
Array(TypeArray),
Union(TypeUnion),
Intersection(TypeIntersection),
}
#[derive(Debug, Clone, Copy)]
pub struct TypeName {
pub path: List<Ident>,
pub name: Ident,
pub generic_args: List<TypeExpr>,
}
#[derive(Debug, Clone, Copy)]
pub struct TypeString {
pub docs: Option<Docs>,
pub value: &'static str,
}
#[derive(Debug, Clone, Copy)]
pub struct TypeTuple {
pub docs: Option<Docs>,
pub elements: List<TypeExpr>,
}
#[derive(Debug, Clone, Copy)]
pub struct TypeObject {
pub docs: Option<Docs>,
pub index_signature: Option<IndexSignature>,
pub fields: List<ObjectField>,
}
#[derive(Debug, Clone, Copy)]
pub struct IndexSignature {
pub docs: Option<Docs>,
pub name: Ident,
pub value: &'static TypeExpr,
}
#[derive(Debug, Clone, Copy)]
pub struct ObjectField {
pub docs: Option<Docs>,
pub name: TypeString,
pub optional: bool,
pub r#type: TypeExpr,
}
#[derive(Debug, Clone, Copy)]
pub struct TypeArray {
pub docs: Option<Docs>,
pub item: &'static TypeExpr,
}
#[derive(Debug, Clone, Copy)]
pub struct TypeUnion {
pub docs: Option<Docs>,
pub members: List<TypeExpr>,
}
#[derive(Debug, Clone, Copy)]
pub struct TypeIntersection {
pub docs: Option<Docs>,
pub members: List<TypeExpr>,
}
#[derive(Debug, Clone, Copy)]
pub struct Ident(pub &'static str);
#[derive(Debug, Clone, Copy)]
pub struct Docs(pub &'static str);
pub type List<T> = &'static [T];
impl TypeExpr {
pub const fn ident(ident: Ident) -> Self {
Self::Name(TypeName::ident(ident))
}
}
impl TypeName {
pub const fn ident(ident: Ident) -> Self {
Self {
path: &[],
name: ident,
generic_args: &[],
}
}
}