some_random_api/structs/
tweet.rs

1use serde::Serialize;
2
3#[derive(Debug, Serialize)]
4pub struct Tweet {
5    pub username: String,
6
7    #[serde(rename = "displayname")]
8    pub display_name: String,
9
10    #[serde(rename = "avatar")]
11    pub avatar_url: String,
12
13    pub comment: String,
14    pub replies: String,
15    pub retweets: String,
16    pub likes: String,
17    pub theme: String,
18}
19
20impl Tweet {
21    /// Create an instance of [`Tweet`]
22    ///
23    /// # Examples
24    ///
25    /// ```
26    /// use some_random_api::Tweet;
27    ///
28    /// Tweet::new(
29    ///     "username",
30    ///     "avatar url",
31    ///     "comment"
32    /// )
33    /// .set_display_name("display name")
34    /// .set_dark_theme(true)
35    /// .set_replies("100K");
36    /// ```
37    pub fn new<T: ToString, U: ToString, V: ToString>(
38        username: T,
39        avatar_url: U,
40        comment: V,
41    ) -> Self {
42        Self {
43            username: username.to_string(),
44            display_name: username.to_string(),
45            avatar_url: avatar_url.to_string(),
46            comment: comment.to_string(),
47            replies: "".into(),
48            retweets: "".into(),
49            likes: "".into(),
50            theme: "".into(),
51        }
52    }
53
54    /// Sets the display name of the tweet author
55    pub fn set_display_name<T: ToString>(mut self, display_name: T) -> Self {
56        self.display_name = display_name.to_string();
57        self
58    }
59
60    /// Sets the tweet reply amount or text
61    pub fn set_replies<T: ToString>(mut self, replies: T) -> Self {
62        self.replies = replies.to_string();
63        self
64    }
65
66    /// Sets the tweet retweet amount or text
67    pub fn set_retweets<T: ToString>(mut self, retweets: T) -> Self {
68        self.retweets = retweets.to_string();
69        self
70    }
71
72    /// Sets the tweet like amount or text
73    pub fn set_likes<T: ToString>(mut self, likes: T) -> Self {
74        self.likes = likes.to_string();
75        self
76    }
77
78    /// Sets whether to use dark theme instead
79    pub fn set_dark_theme(mut self, dark_theme: bool) -> Self {
80        if dark_theme {
81            self.theme = "dark".into();
82        }
83
84        self
85    }
86}