Skip to main content

twapi_v2/responses/
includes.rs

1use crate::responses::{media::Media, places::Places, polls::Polls, tweets::Tweets, users::Users};
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
5pub struct Includes {
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub media: Option<Vec<Media>>,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub places: Option<Vec<Places>>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub polls: Option<Vec<Polls>>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub tweets: Option<Vec<Tweets>>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub users: Option<Vec<Users>>,
16    #[serde(flatten)]
17    pub extra: std::collections::HashMap<String, serde_json::Value>,
18}
19
20impl Includes {
21    pub fn is_empty_extra(&self) -> bool {
22        let res = self.extra.is_empty()
23            && self
24                .media
25                .as_ref()
26                .map(|it| it.iter().all(|item| item.is_empty_extra()))
27                .unwrap_or(true)
28            && self
29                .places
30                .as_ref()
31                .map(|it| it.iter().all(|item| item.is_empty_extra()))
32                .unwrap_or(true)
33            && self
34                .polls
35                .as_ref()
36                .map(|it| it.iter().all(|item| item.is_empty_extra()))
37                .unwrap_or(true)
38            && self
39                .tweets
40                .as_ref()
41                .map(|it| it.iter().all(|item| item.is_empty_extra()))
42                .unwrap_or(true)
43            && self
44                .users
45                .as_ref()
46                .map(|it| it.iter().all(|item| item.is_empty_extra()))
47                .unwrap_or(true);
48        if !res {
49            println!("Includes {:?}", self.extra);
50        }
51        res
52    }
53}