layline_codegen/model/
dispatch.rs1use alloc::string::String;
4use alloc::vec::Vec;
5
6use super::Derive;
7
8use super::Scalar;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct DispatchDef {
15 pub name: String,
17 pub id: Scalar,
19 pub arms: Vec<DispatchArm>,
21 pub other: String,
23 pub doc: Option<String>,
25 pub derives: Vec<Derive>,
27}
28
29impl DispatchDef {
30 #[must_use]
32 pub fn new(name: &str, id: Scalar, arms: Vec<DispatchArm>) -> Self {
33 Self {
34 name: String::from(name),
35 id,
36 arms,
37 other: String::from("Unknown"),
38 doc: None,
39 derives: Vec::new(),
40 }
41 }
42
43 #[must_use]
45 pub fn with_derives(self, derives: Vec<Derive>) -> Self {
46 Self { derives, ..self }
47 }
48
49 #[must_use]
51 pub fn with_other(self, other: &str) -> Self {
52 Self { other: String::from(other), ..self }
53 }
54
55 #[must_use]
57 pub fn with_doc(self, doc: &str) -> Self {
58 Self { doc: Some(String::from(doc)), ..self }
59 }
60}
61
62#[derive(Debug, Clone, PartialEq, Eq)]
64#[non_exhaustive]
65pub struct DispatchArm {
66 pub id: i64,
68 pub name: String,
70 pub ty: String,
72 pub doc: Option<String>,
74}
75
76impl DispatchArm {
77 #[must_use]
79 pub fn new(id: i64, name: &str, ty: &str) -> Self {
80 Self { id, name: String::from(name), ty: String::from(ty), doc: None }
81 }
82
83 #[must_use]
85 pub fn with_doc(self, doc: &str) -> Self {
86 Self { doc: Some(String::from(doc)), ..self }
87 }
88}