twilight_util/builder/message/
checkbox_group.rs1use twilight_model::channel::message::component::{CheckboxGroup, CheckboxGroupOption};
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5#[must_use = "must be built into a checkbox group"]
6pub struct CheckboxGroupBuilder(CheckboxGroup);
7impl CheckboxGroupBuilder {
8 pub fn new(custom_id: impl Into<String>) -> Self {
10 Self(CheckboxGroup {
11 id: None,
12 custom_id: custom_id.into(),
13 options: vec![],
14 min_values: None,
15 max_values: None,
16 required: None,
17 })
18 }
19
20 pub const fn id(mut self, id: i32) -> Self {
22 self.0.id.replace(id);
23
24 self
25 }
26
27 pub fn option(mut self, option: impl Into<CheckboxGroupOption>) -> Self {
29 self.0.options.push(option.into());
30
31 self
32 }
33
34 pub const fn min_values(mut self, min_values: u8) -> Self {
36 self.0.min_values.replace(min_values);
37
38 self
39 }
40
41 pub const fn max_values(mut self, max_values: u8) -> Self {
43 self.0.max_values.replace(max_values);
44
45 self
46 }
47
48 pub const fn required(mut self, required: bool) -> Self {
50 self.0.required.replace(required);
51
52 self
53 }
54
55 pub fn build(self) -> CheckboxGroup {
57 self.0
58 }
59}
60
61#[derive(Clone, Debug, Eq, PartialEq)]
63#[must_use = "must be built into a checkbox group option"]
64pub struct CheckboxGroupOptionBuilder(CheckboxGroupOption);
65
66impl CheckboxGroupOptionBuilder {
67 pub fn new(value: impl Into<String>, label: impl Into<String>) -> Self {
69 Self(CheckboxGroupOption {
70 value: value.into(),
71 label: label.into(),
72 description: None,
73 default: None,
74 })
75 }
76
77 pub const fn default(mut self, default: bool) -> Self {
79 self.0.default.replace(default);
80
81 self
82 }
83
84 pub fn description(mut self, description: impl Into<String>) -> Self {
86 self.0.description.replace(description.into());
87
88 self
89 }
90
91 pub fn build(self) -> CheckboxGroupOption {
93 self.0
94 }
95}