use indexmap::IndexMap;
#[derive(Debug, Clone, PartialEq)]
pub struct TypeGraph {
pub namespace: String,
pub root_elements: Vec<RootElement>,
pub types: IndexMap<String, TypeDef>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RootElement {
pub xml_name: String,
pub type_name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TypeDef {
Struct(StructDef),
Enum(EnumDef),
Newtype(NewtypeDef),
CodeEnum(CodeEnumDef),
ValueWithAttr(ValueWithAttrDef),
Opaque(OpaqueDef),
}
impl TypeDef {
pub fn name(&self) -> &str {
match self {
TypeDef::Struct(d) => &d.name,
TypeDef::Enum(d) => &d.name,
TypeDef::Newtype(d) => &d.name,
TypeDef::CodeEnum(d) => &d.name,
TypeDef::ValueWithAttr(d) => &d.name,
TypeDef::Opaque(d) => &d.name,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct StructDef {
pub name: String,
pub fields: Vec<FieldDef>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FieldDef {
pub xml_name: String,
pub rust_name: String,
pub type_ref: TypeRef,
pub cardinality: Cardinality,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Cardinality {
Required,
Optional,
Vec,
BoundedVec(u32),
}
#[derive(Debug, Clone, PartialEq)]
pub struct EnumDef {
pub name: String,
pub variants: Vec<VariantDef>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct VariantDef {
pub xml_name: String,
pub rust_name: String,
pub type_ref: TypeRef,
}
#[derive(Debug, Clone, PartialEq)]
pub struct NewtypeDef {
pub name: String,
pub inner: RustType,
pub constraints: Vec<Constraint>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CodeEnumDef {
pub name: String,
pub codes: Vec<CodeValue>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CodeValue {
pub xml_value: String,
pub rust_name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ValueWithAttrDef {
pub name: String,
pub value_type: TypeRef,
pub attributes: Vec<AttrDef>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AttrDef {
pub xml_name: String,
pub rust_name: String,
pub type_ref: TypeRef,
pub required: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct OpaqueDef {
pub name: String,
pub namespace: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TypeRef {
Named(String),
Builtin(RustType),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RustType {
String,
Bool,
Decimal,
Date,
DateTime,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Constraint {
MinLength(u64),
MaxLength(u64),
Pattern(String),
MinInclusive(String),
MaxInclusive(String),
TotalDigits(u32),
FractionDigits(u32),
}