1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::convert;
use serde::{Deserialize, Serialize};
pub mod mrkdwn;
pub mod plain;
pub use mrkdwn::Contents as Mrkdwn;
pub use plain::Contents as Plain;
#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Text {
Mrkdwn(mrkdwn::Contents),
#[serde(rename = "plain_text")]
Plain(plain::Contents),
}
impl Text {
pub fn copy_from<T: Into<Self> + Clone>(contents: &T) -> Self {
contents.clone().into()
}
}
convert!(impl From<mrkdwn::Contents> for Text => |contents| Text::Mrkdwn(contents));
convert!(impl From<plain::Contents> for Text => |contents| Text::Plain(contents));
impl AsRef<str> for Text {
fn as_ref(&self) -> &str {
match self {
Self::Mrkdwn(cts) => cts.as_ref(),
Self::Plain(cts) => cts.as_ref(),
}
}
}