twilight_util/builder/message/
text_display.rs1use twilight_model::channel::message::component::TextDisplay;
2
3#[derive(Clone, Debug, Eq, PartialEq)]
5#[must_use = "must be built into a text display"]
6pub struct TextDisplayBuilder(TextDisplay);
7
8impl TextDisplayBuilder {
9 pub fn new(content: impl Into<String>) -> Self {
11 Self(TextDisplay {
12 content: content.into(),
13 id: None,
14 })
15 }
16
17 pub fn id(mut self, id: i32) -> Self {
19 self.0.id.replace(id);
20
21 self
22 }
23
24 pub fn build(self) -> TextDisplay {
26 self.0
27 }
28}
29
30impl From<TextDisplayBuilder> for TextDisplay {
31 fn from(builder: TextDisplayBuilder) -> Self {
32 builder.build()
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39 use static_assertions::assert_impl_all;
40 use std::fmt::Debug;
41
42 assert_impl_all!(TextDisplayBuilder: Clone, Debug, Eq, PartialEq, Send, Sync);
43 assert_impl_all!(TextDisplay: From<TextDisplayBuilder>);
44
45 #[test]
46 fn builder() {
47 let expected = TextDisplay {
48 content: "Lorem ipsum".to_string(),
49 id: None,
50 };
51
52 let actual = TextDisplayBuilder::new("Lorem ipsum").build();
53
54 assert_eq!(actual, expected);
55 }
56}