layline_codegen/model/
enumeration.rs1use alloc::string::String;
4use alloc::vec::Vec;
5
6use super::Scalar;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
10#[non_exhaustive]
11pub struct EnumDef {
12 pub name: String,
14 pub repr: Scalar,
16 pub variants: Vec<Variant>,
18 pub other: Option<String>,
20 pub doc: Option<String>,
22}
23
24impl EnumDef {
25 #[must_use]
27 pub fn new(name: &str, repr: Scalar, variants: Vec<Variant>) -> Self {
28 Self { name: String::from(name), repr, variants, other: None, doc: None }
29 }
30
31 #[must_use]
33 pub fn with_other(self, other: &str) -> Self {
34 Self { other: Some(String::from(other)), ..self }
35 }
36
37 #[must_use]
39 pub fn with_doc(self, doc: &str) -> Self {
40 Self { doc: Some(String::from(doc)), ..self }
41 }
42}
43
44#[derive(Debug, Clone, PartialEq, Eq)]
46#[non_exhaustive]
47pub struct Variant {
48 pub value: i64,
50 pub name: String,
52 pub doc: Option<String>,
54}
55
56impl Variant {
57 #[must_use]
59 pub fn new(value: i64, name: &str) -> Self {
60 Self { value, name: String::from(name), doc: None }
61 }
62
63 #[must_use]
65 pub fn with_doc(self, doc: &str) -> Self {
66 Self { doc: Some(String::from(doc)), ..self }
67 }
68}