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 serde::Serialize;
#[derive(Debug, Serialize)]
pub struct Tweet {
pub username: String,
#[serde(rename = "displayname")]
pub display_name: String,
#[serde(rename = "avatar")]
pub avatar_url: String,
pub comment: String,
pub replies: String,
pub retweets: String,
pub likes: String,
pub theme: String,
}
impl Tweet {
/// Create an instance of [`Tweet`]
///
/// # Examples
///
/// ```
/// use some_random_api::Tweet;
///
/// Tweet::new(
/// "username",
/// "avatar url",
/// "comment"
/// )
/// .set_display_name("display name")
/// .set_dark_theme(true)
/// .set_replies("100K");
/// ```
pub fn new<T: ToString, U: ToString, V: ToString>(
username: T,
avatar_url: U,
comment: V,
) -> Self {
Self {
username: username.to_string(),
display_name: username.to_string(),
avatar_url: avatar_url.to_string(),
comment: comment.to_string(),
replies: "".into(),
retweets: "".into(),
likes: "".into(),
theme: "".into(),
}
}
/// Sets the display name of the tweet author
pub fn set_display_name<T: ToString>(mut self, display_name: T) -> Self {
self.display_name = display_name.to_string();
self
}
/// Sets the tweet reply amount or text
pub fn set_replies<T: ToString>(mut self, replies: T) -> Self {
self.replies = replies.to_string();
self
}
/// Sets the tweet retweet amount or text
pub fn set_retweets<T: ToString>(mut self, retweets: T) -> Self {
self.retweets = retweets.to_string();
self
}
/// Sets the tweet like amount or text
pub fn set_likes<T: ToString>(mut self, likes: T) -> Self {
self.likes = likes.to_string();
self
}
/// Sets whether to use dark theme instead
pub fn set_dark_theme(mut self, dark_theme: bool) -> Self {
if dark_theme {
self.theme = "dark".into();
}
self
}
}