Skip to main content

twapi_v2/responses/
referenced_tweets.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
4pub struct ReferencedTweets {
5    #[serde(skip_serializing_if = "Option::is_none")]
6    pub id: Option<String>,
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub r#type: Option<Type>,
9    #[serde(flatten)]
10    pub extra: std::collections::HashMap<String, serde_json::Value>,
11}
12
13impl ReferencedTweets {
14    pub fn is_empty_extra(&self) -> bool {
15        let res = self.extra.is_empty();
16        if !res {
17            println!("ReferencedTweets {:?}", self.extra);
18        }
19        res
20    }
21}
22
23#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
24pub enum Type {
25    #[serde(rename = "retweeted")]
26    #[default]
27    Retweeted,
28    #[serde(rename = "quoted")]
29    Quoted,
30    #[serde(rename = "replied_to")]
31    RepliedTo,
32}
33
34impl std::fmt::Display for Type {
35    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
36        match self {
37            Self::Retweeted => write!(f, "retweeted"),
38            Self::Quoted => write!(f, "quoted"),
39            Self::RepliedTo => write!(f, "replied_to"),
40        }
41    }
42}