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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use mime::Mime;
use serde::{Deserialize, Serialize};
use crate::types::PhotoSize;
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Animation {
pub file_id: String,
pub file_unique_id: String,
pub width: u32,
pub height: u32,
pub duration: u32,
pub thumb: Option<PhotoSize>,
pub file_name: Option<String>,
#[serde(with = "crate::types::non_telegram_types::mime::opt_deser")]
pub mime_type: Option<Mime>,
pub file_size: Option<u32>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn deserialize() {
let json = r#"{
"file_id":"id",
"file_unique_id":"",
"width":320,
"height":320,
"duration":59,
"thumb":{
"file_id":"id",
"file_unique_id":"",
"width":320,
"height":320,
"file_size":3452
},
"file_name":"some",
"mime_type":"video/gif",
"file_size":6500}"#;
let expected = Animation {
file_id: "id".to_string(),
file_unique_id: "".to_string(),
width: 320,
height: 320,
duration: 59,
thumb: Some(PhotoSize {
file_id: "id".to_string(),
file_unique_id: "".to_string(),
width: 320,
height: 320,
file_size: Some(3452),
}),
file_name: Some("some".to_string()),
mime_type: Some("video/gif".parse().unwrap()),
file_size: Some(6500),
};
let actual = serde_json::from_str::<Animation>(json).unwrap();
assert_eq!(actual, expected)
}
}