layline_codegen/model/
dispatch.rs1use alloc::string::String;
4use alloc::vec::Vec;
5
6use super::Scalar;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
11#[non_exhaustive]
12pub struct DispatchDef {
13 pub name: String,
15 pub id: Scalar,
17 pub arms: Vec<DispatchArm>,
19 pub other: String,
21 pub doc: Option<String>,
23}
24
25impl DispatchDef {
26 #[must_use]
28 pub fn new(name: &str, id: Scalar, arms: Vec<DispatchArm>) -> Self {
29 Self { name: String::from(name), id, arms, other: String::from("Unknown"), doc: None }
30 }
31
32 #[must_use]
34 pub fn with_other(self, other: &str) -> Self {
35 Self { other: String::from(other), ..self }
36 }
37
38 #[must_use]
40 pub fn with_doc(self, doc: &str) -> Self {
41 Self { doc: Some(String::from(doc)), ..self }
42 }
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
47#[non_exhaustive]
48pub struct DispatchArm {
49 pub id: i64,
51 pub name: String,
53 pub ty: String,
55 pub doc: Option<String>,
57}
58
59impl DispatchArm {
60 #[must_use]
62 pub fn new(id: i64, name: &str, ty: &str) -> Self {
63 Self { id, name: String::from(name), ty: String::from(ty), doc: None }
64 }
65
66 #[must_use]
68 pub fn with_doc(self, doc: &str) -> Self {
69 Self { doc: Some(String::from(doc)), ..self }
70 }
71}