charming_fork_zephyr/element/
boundary_gap.rs1use serde::{ser::SerializeSeq, Serialize};
2
3pub enum BoundaryGap {
13 CategoryAxis(bool),
14 NonCategoryAxis(String, String),
15}
16
17impl Serialize for BoundaryGap {
18 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
19 where
20 S: serde::ser::Serializer,
21 {
22 match self {
23 BoundaryGap::CategoryAxis(b) => b.serialize(serializer),
24 BoundaryGap::NonCategoryAxis(min, max) => {
25 let mut s = serializer.serialize_seq(Some(2))?;
26 s.serialize_element(min)?;
27 s.serialize_element(max)?;
28 s.end()
29 }
30 }
31 }
32}
33
34impl From<bool> for BoundaryGap {
35 fn from(b: bool) -> Self {
36 BoundaryGap::CategoryAxis(b)
37 }
38}
39
40impl From<(&str, &str)> for BoundaryGap {
41 fn from((min, max): (&str, &str)) -> Self {
42 BoundaryGap::NonCategoryAxis(min.to_string(), max.to_string())
43 }
44}