1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use serde::{Deserialize, Serialize};
use crate::convert;
use crate::val_helpr::ValidationResult;
pub mod button;
pub use button::Contents as Button;
pub mod select;
pub use select::Select;
#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum BlockElement<'a> {
Button(Button),
Checkboxes,
DatePicker,
Image,
MultiSelect,
OverflowMenu,
PlainInput,
RadioButtons,
#[serde(rename = "channels_select")]
SelectPublicChannel(select::PublicChannel<'a>),
}
impl<'a> BlockElement<'a> {
pub fn validate(&self) -> ValidationResult {
match self {
Self::Button(cts) => cts.validate(),
Self::SelectPublicChannel(cts) => cts.validate(),
rest => todo!("validation not implemented for {:?}", rest),
}
}
}
convert!(impl From<Button> for BlockElement<'static> => |b| BlockElement::Button(b));
convert!(impl<'a> From<Select<'a>> for BlockElement<'a>
=> |s| match s {
Select::PublicChannel(s) => s.into(),
_ => todo!()
}
);
use select::PublicChannel as SelectPublicChannel;
convert!(impl<'a> From<SelectPublicChannel<'a>> for BlockElement<'a> => |s| BlockElement::SelectPublicChannel(s));