tg_flows/types/
animation.rs1use mime::Mime;
2use serde::{Deserialize, Serialize};
3
4use crate::types::{FileMeta, PhotoSize};
5
6#[serde_with_macros::skip_serializing_none]
11#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
12pub struct Animation {
13 #[serde(flatten)]
15 pub file: FileMeta,
16
17 pub width: u32,
19
20 pub height: u32,
22
23 pub duration: u32,
25
26 pub thumb: Option<PhotoSize>,
28
29 pub file_name: Option<String>,
31
32 #[serde(with = "crate::types::non_telegram_types::mime::opt_deser")]
34 pub mime_type: Option<Mime>,
35}
36
37#[cfg(test)]
38mod tests {
39 use crate::types::FileMeta;
40
41 use super::*;
42
43 #[test]
44 fn deserialize() {
45 let json = r#"{
46 "file_id":"id",
47 "file_unique_id":"",
48 "width":320,
49 "height":320,
50 "duration":59,
51 "thumb":{
52 "file_id":"id",
53 "file_unique_id":"",
54 "width":320,
55 "height":320,
56 "file_size":3452
57 },
58 "file_name":"some",
59 "mime_type":"video/gif",
60 "file_size":6500}"#;
61 let expected = Animation {
62 file: FileMeta {
63 id: "id".to_string(),
64 unique_id: "".to_string(),
65 size: 6500,
66 },
67 width: 320,
68 height: 320,
69 duration: 59,
70 thumb: Some(PhotoSize {
71 file: FileMeta {
72 id: "id".to_owned(),
73 unique_id: "".to_owned(),
74 size: 3452,
75 },
76 width: 320,
77 height: 320,
78 }),
79 file_name: Some("some".to_string()),
80 mime_type: Some("video/gif".parse().unwrap()),
81 };
82 let actual = serde_json::from_str::<Animation>(json).unwrap();
83 assert_eq!(actual, expected)
84 }
85}