use alloc::{
string::{String, ToString},
vec::Vec,
};
#[derive(Clone, Debug)]
pub struct TypeDescription {
pub docs: Vec<String>,
pub name: String,
pub contents: TypeContents,
}
impl TypeDescription {
pub const PLACEHOLDER: TypeDescription = TypeDescription {
docs: Vec::new(),
name: String::new(),
contents: TypeContents::NotSpecified,
};
}
impl TypeDescription {
pub fn new(docs: &[&str], name: String, contents: TypeContents) -> Self {
TypeDescription {
docs: docs.iter().map(|s| s.to_string()).collect(),
name,
contents,
}
}
}
#[derive(Clone, Debug)]
pub enum TypeContents {
NotSpecified,
Enum(Vec<EnumVariantDescription>),
Struct(Vec<StructFieldDescription>),
ExplicitEnum(Vec<ExplicitEnumVariantDescription>),
}
impl TypeContents {
pub fn is_specified(&self) -> bool {
!matches!(*self, TypeContents::NotSpecified)
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EnumVariantDescription {
pub docs: Vec<String>,
pub name: String,
pub discriminant: usize,
pub fields: Vec<StructFieldDescription>,
}
impl EnumVariantDescription {
pub fn new(
docs: &[&str],
name: &str,
discriminant: usize,
fields: Vec<StructFieldDescription>,
) -> Self {
EnumVariantDescription {
docs: docs.iter().map(|s| s.to_string()).collect(),
name: name.to_string(),
discriminant,
fields,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StructFieldDescription {
pub docs: Vec<String>,
pub name: String,
pub field_type: String,
}
impl StructFieldDescription {
pub fn new(docs: &[&str], name: &str, field_type: String) -> Self {
Self {
docs: docs.iter().map(|s| s.to_string()).collect(),
name: name.to_string(),
field_type,
}
}
}
#[derive(Clone, Debug)]
pub struct ExplicitEnumVariantDescription {
pub docs: Vec<String>,
pub name: String,
}
impl ExplicitEnumVariantDescription {
pub fn new(docs: &[&str], name: &str) -> Self {
Self {
docs: docs.iter().map(|s| s.to_string()).collect(),
name: name.to_string(),
}
}
}