twilight_util/builder/message/
separator.rs1use twilight_model::channel::message::component::{Separator, SeparatorSpacingSize};
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5#[must_use = "must be built into a separator"]
6pub struct SeparatorBuilder(Separator);
7
8impl SeparatorBuilder {
9 pub const fn new() -> Self {
11 Self(Separator {
12 id: None,
13 divider: None,
14 spacing: None,
15 })
16 }
17
18 pub fn id(mut self, id: i32) -> Self {
20 self.0.id.replace(id);
21
22 self
23 }
24
25 pub fn divider(mut self, divider: bool) -> Self {
27 self.0.divider.replace(divider);
28
29 self
30 }
31
32 pub fn spacing(mut self, spacing: SeparatorSpacingSize) -> Self {
34 self.0.spacing.replace(spacing);
35
36 self
37 }
38
39 pub const fn build(self) -> Separator {
41 self.0
42 }
43}
44
45impl Default for SeparatorBuilder {
46 fn default() -> Self {
47 Self::new()
48 }
49}
50
51impl From<SeparatorBuilder> for Separator {
52 fn from(builder: SeparatorBuilder) -> Self {
53 builder.build()
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60 use static_assertions::assert_impl_all;
61 use std::fmt::Debug;
62
63 assert_impl_all!(SeparatorBuilder: Clone, Debug, Eq, PartialEq, Send, Sync);
64 assert_impl_all!(Separator: From<SeparatorBuilder>);
65
66 #[test]
67 fn builder() {
68 let expected = Separator {
69 id: None,
70 divider: None,
71 spacing: None,
72 };
73
74 let actual = SeparatorBuilder::new().build();
75
76 assert_eq!(actual, expected);
77 }
78}