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
use crate::composition::text::Text::Plain;
use crate::composition::text::{PlainText, Text};
use serde::Serialize;
#[derive(Debug, Default, Serialize, Clone)]
pub struct OptionObject {
text: Text,
value: String,
#[serde(skip_serializing_if = "Option::is_none")]
url: Option<String>,
}
impl OptionObject {
pub fn new(text: impl Into<PlainText>, value: impl Into<String>) -> Self {
OptionObject {
text: Plain(text.into()),
value: value.into(),
..OptionObject::default()
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_ser_new() {
let option = OptionObject::new(PlainText::new("text"), "value");
let json = serde_json::to_string_pretty(&option).unwrap_or("".to_string());
let expected = r#"{
"text": {
"type": "plain_text",
"text": "text"
},
"value": "value"
}"#;
assert_eq!(json, expected.to_string());
}
}