charming_fork_zephyr/component/
parallel_axis.rs

1use serde::Serialize;
2
3use crate::element::{AxisType, NameLocation};
4
5#[derive(Serialize)]
6#[serde(rename_all = "camelCase")]
7pub struct ParallelAxis {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    dim: Option<i64>,
10
11    #[serde(skip_serializing_if = "Option::is_none")]
12    parallel_index: Option<i64>,
13
14    #[serde(skip_serializing_if = "Option::is_none")]
15    realtime: Option<bool>,
16
17    #[serde(skip_serializing_if = "Option::is_none")]
18    #[serde(rename = "type")]
19    type_: Option<AxisType>,
20
21    #[serde(skip_serializing_if = "Option::is_none")]
22    name: Option<String>,
23
24    #[serde(skip_serializing_if = "Option::is_none")]
25    name_location: Option<NameLocation>,
26
27    #[serde(skip_serializing_if = "Option::is_none")]
28    name_gap: Option<i64>,
29
30    #[serde(skip_serializing_if = "Option::is_none")]
31    inverse: Option<bool>,
32
33    #[serde(skip_serializing_if = "Option::is_none")]
34    max: Option<i64>,
35
36    #[serde(skip_serializing_if = "Option::is_none")]
37    min: Option<i64>,
38
39    #[serde(skip_serializing_if = "Vec::is_empty")]
40    data: Vec<String>,
41}
42
43impl ParallelAxis {
44    pub fn new() -> Self {
45        Self {
46            dim: None,
47            parallel_index: None,
48            realtime: None,
49            type_: None,
50            name: None,
51            name_location: None,
52            name_gap: None,
53            inverse: None,
54            max: None,
55            min: None,
56            data: vec![],
57        }
58    }
59
60    pub fn dim<F: Into<i64>>(mut self, dim: F) -> Self {
61        self.dim = Some(dim.into());
62        self
63    }
64
65    pub fn parallel_index<F: Into<i64>>(mut self, parallel_index: F) -> Self {
66        self.parallel_index = Some(parallel_index.into());
67        self
68    }
69
70    pub fn realtime(mut self, realtime: bool) -> Self {
71        self.realtime = Some(realtime);
72        self
73    }
74
75    pub fn type_<S: Into<AxisType>>(mut self, type_: S) -> Self {
76        self.type_ = Some(type_.into());
77        self
78    }
79
80    pub fn name<S: Into<String>>(mut self, name: S) -> Self {
81        self.name = Some(name.into());
82        self
83    }
84
85    pub fn name_location<E: Into<NameLocation>>(mut self, name_location: E) -> Self {
86        self.name_location = Some(name_location.into());
87        self
88    }
89
90    pub fn name_gap<F: Into<i64>>(mut self, name_gap: F) -> Self {
91        self.name_gap = Some(name_gap.into());
92        self
93    }
94
95    pub fn inverse(mut self, inverse: bool) -> Self {
96        self.inverse = Some(inverse);
97        self
98    }
99
100    pub fn max<F: Into<i64>>(mut self, max: F) -> Self {
101        self.max = Some(max.into());
102        self
103    }
104
105    pub fn min<F: Into<i64>>(mut self, min: F) -> Self {
106        self.min = Some(min.into());
107        self
108    }
109
110    pub fn data<S: Into<String>>(mut self, data: Vec<S>) -> Self {
111        self.data = data.into_iter().map(|s| s.into()).collect();
112        self
113    }
114}