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>,
pub prefix: u32,
pub other_doc: Option<String>,
pub other_body: Option<String>,
}
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(),
prefix: 0,
other_doc: None,
other_body: None,
}
}
#[must_use]
pub fn with_other_doc(self, doc: &str) -> Self {
Self { other_doc: Some(String::from(doc)), ..self }
}
#[must_use]
pub fn with_prefix(self, prefix: u32) -> Self {
Self { prefix, ..self }
}
#[must_use]
pub fn with_other_body(self, ty: &str) -> Self {
Self { other_body: Some(String::from(ty)), ..self }
}
#[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 }
}
}