use alloc::string::String;
use alloc::vec::Vec;
use super::Derive;
use super::Scalar;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct EnumDef {
pub name: String,
pub repr: Scalar,
pub variants: Vec<Variant>,
pub other: Option<String>,
pub doc: Option<String>,
pub default: Option<String>,
pub derives: Vec<Derive>,
pub other_doc: Option<String>,
}
impl EnumDef {
#[must_use]
pub fn new(name: &str, repr: Scalar, variants: Vec<Variant>) -> Self {
Self {
name: String::from(name),
repr,
variants,
other: None,
doc: None,
default: None,
derives: Vec::new(),
other_doc: 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_default(self, variant: &str) -> Self {
Self { default: Some(String::from(variant)), ..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: Some(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 Variant {
pub value: i64,
pub name: String,
pub doc: Option<String>,
}
impl Variant {
#[must_use]
pub fn new(value: i64, name: &str) -> Self {
Self { value, name: String::from(name), doc: None }
}
#[must_use]
pub fn with_doc(self, doc: &str) -> Self {
Self { doc: Some(String::from(doc)), ..self }
}
}