abineo_messaging/
content.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4#[serde(rename_all = "camelCase")]
5#[non_exhaustive]
6pub enum Content {
7    Title(String),
8    Subtitle(String),
9    Text(String),
10    Secret(String),
11}
12
13impl Content {
14    pub fn builder() -> ContentBuilder {
15        ContentBuilder::default()
16    }
17}
18
19// -------------------------------------------------------------------------------------------------
20
21#[derive(Debug, Clone, Default)]
22pub struct ContentBuilder {
23    items: Vec<Content>,
24}
25
26impl ContentBuilder {
27    pub fn title<T: Into<String>>(mut self, value: T) -> Self {
28        self.items.push(Content::Title(value.into()));
29        self
30    }
31
32    pub fn subtitle<T: Into<String>>(mut self, value: T) -> Self {
33        self.items.push(Content::Subtitle(value.into()));
34        self
35    }
36
37    pub fn text<T: Into<String>>(mut self, value: T) -> Self {
38        self.items.push(Content::Text(value.into()));
39        self
40    }
41
42    pub fn secret<T: Into<String>>(mut self, value: T) -> Self {
43        self.items.push(Content::Secret(value.into()));
44        self
45    }
46
47    pub fn build(self) -> Vec<Content> {
48        self.items
49    }
50}
51
52impl Into<Vec<Content>> for ContentBuilder {
53    fn into(self) -> Vec<Content> {
54        self.build()
55    }
56}