twilight_util/builder/message/
action_row.rs1use twilight_model::channel::message::{component::ActionRow, Component};
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5#[must_use = "must be built into an ActionRow"]
6pub struct ActionRowBuilder(ActionRow);
7
8impl ActionRowBuilder {
9 pub const fn new() -> Self {
11 Self(ActionRow {
12 id: None,
13 components: Vec::new(),
14 })
15 }
16
17 pub fn component(mut self, component: impl Into<Component>) -> Self {
19 self.0.components.push(component.into());
20
21 self
22 }
23
24 pub fn id(mut self, id: i32) -> Self {
26 self.0.id.replace(id);
27
28 self
29 }
30
31 pub fn build(self) -> ActionRow {
33 self.0
34 }
35}
36
37impl Default for ActionRowBuilder {
38 fn default() -> Self {
39 Self::new()
40 }
41}
42
43impl From<ActionRowBuilder> for ActionRow {
44 fn from(builder: ActionRowBuilder) -> Self {
45 builder.build()
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52 use static_assertions::assert_impl_all;
53 use std::fmt::Debug;
54
55 assert_impl_all!(ActionRowBuilder: Clone, Debug, Eq, PartialEq, Send, Sync);
56 assert_impl_all!(ActionRow: From<ActionRowBuilder>);
57
58 #[test]
59 fn builder() {
60 let expected = ActionRow {
61 id: None,
62 components: Vec::new(),
63 };
64
65 let actual = ActionRowBuilder::new().build();
66
67 assert_eq!(actual, expected);
68 }
69}