use vize_l0::String;
pub mod schema {
pub const SUMMARY: u16 = 1;
pub const SIGNATURE: u16 = 1;
pub const PROPS: u16 = 1;
pub const EMITS: u16 = 1;
pub const SLOTS: u16 = 1;
pub const REACTIVITY: u16 = 1;
pub const COMPONENTS: u16 = 1;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum Facet {
Signature = 0,
Prop = 1,
Emit = 2,
Slot = 3,
Reactivity = 4,
Component = 5,
}
impl Facet {
pub const ALL: [Self; 6] = [
Self::Signature,
Self::Prop,
Self::Emit,
Self::Slot,
Self::Reactivity,
Self::Component,
];
#[must_use]
pub const fn group(self) -> &'static str {
match self {
Self::Signature => "component-signature",
Self::Prop => "prop-types",
Self::Emit => "emit-types",
Self::Slot => "slot-types",
Self::Reactivity => "reactivity-classes",
Self::Component => "component-references",
}
}
#[must_use]
pub const fn schema(self) -> u16 {
match self {
Self::Signature => schema::SIGNATURE,
Self::Prop => schema::PROPS,
Self::Emit => schema::EMITS,
Self::Slot => schema::SLOTS,
Self::Reactivity => schema::REACTIVITY,
Self::Component => schema::COMPONENTS,
}
}
#[must_use]
pub fn from_group_name(group: &str) -> Option<Self> {
Self::ALL.into_iter().find(|facet| facet.group() == group)
}
pub fn from_alpha_group(group: &str, schema: u16) -> Result<Self, SummaryError> {
let Some(facet) = Self::from_group_name(group) else {
return Err(SummaryError::NotInterface {
group: String::from(group),
});
};
if schema != facet.schema() {
return Err(SummaryError::Schema {
group: String::from(group),
expected: facet.schema(),
found: schema,
});
}
Ok(facet)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SummaryError {
BadName { facet: Facet, name: String },
BadContract { facet: Facet, name: String },
Duplicate { facet: Facet, name: String },
Unknown { facet: Facet, name: String },
NotInterface { group: String },
Schema {
group: String,
expected: u16,
found: u16,
},
EmptyConsumer,
DuplicateUse { facet: Facet, name: String },
}