use alloc::string::String;
use alloc::vec::Vec;
use super::Derive;
use super::Scalar;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct DispatchDef {
pub name: String,
pub id: Scalar,
pub arms: Vec<DispatchArm>,
pub other: String,
pub doc: Option<String>,
pub derives: Vec<Derive>,
}
impl DispatchDef {
#[must_use]
pub fn new(name: &str, id: Scalar, arms: Vec<DispatchArm>) -> Self {
Self {
name: String::from(name),
id,
arms,
other: String::from("Unknown"),
doc: None,
derives: Vec::new(),
}
}
#[must_use]
pub fn with_derives(self, derives: Vec<Derive>) -> Self {
Self { derives, ..self }
}
#[must_use]
pub fn with_other(self, other: &str) -> Self {
Self { other: String::from(other), ..self }
}
#[must_use]
pub fn with_doc(self, doc: &str) -> Self {
Self { doc: Some(String::from(doc)), ..self }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct DispatchArm {
pub id: i64,
pub name: String,
pub ty: String,
pub doc: Option<String>,
}
impl DispatchArm {
#[must_use]
pub fn new(id: i64, name: &str, ty: &str) -> Self {
Self { id, name: String::from(name), ty: String::from(ty), doc: None }
}
#[must_use]
pub fn with_doc(self, doc: &str) -> Self {
Self { doc: Some(String::from(doc)), ..self }
}
}