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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
macro_rules! string_enums {
(
$(
$(#[$attr:meta])*
pub enum $E:ident {
$(
$(#[$v_attr:meta])*
:$V:ident($by:expr)
),*;
$(#[$u_attr:meta])*
:$U:ident(_),
}
)*
) => {
$(
$(#[$attr])*
pub enum $E {
$(
$(#[$v_attr])*
$V,
)*
$(#[$u_attr])*
$U(String),
}
impl ::serde::Deserialize for $E {
fn deserialize<D: ::serde::Deserializer>(d: D) -> ::std::result::Result<Self, D::Error> {
struct V;
impl ::serde::de::Visitor for V {
type Value = $E;
fn visit_str<E>(self, s: &str) -> ::std::result::Result<$E, E> {
match s {
$($by => Ok($E::$V),)*
_ => Ok($E::$U(s.to_owned())),
}
}
fn visit_string<E>(self, s: String) -> ::std::result::Result<$E, E> {
match s.as_str() {
$($by => Ok($E::$V),)*
_ => Ok($E::$U(s)),
}
}
fn expecting(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "a string")
}
}
d.deserialize_string(V)
}
}
impl ::std::convert::AsRef<str> for $E {
fn as_ref(&self) -> &str {
match *self {
$($E::$V => $by,)*
$E::$U(ref s) => s,
}
}
}
impl ::std::cmp::PartialEq for $E {
fn eq(&self, other: &$E) -> bool {
match *self {
$($E::$V => match *other {
$E::$V => true,
$E::$U(ref s) if $by == s => true,
_ => false,
},)*
$E::$U(ref s) => match *other {
$($E::$V => $by == s,)*
$E::$U(ref t) => s == t,
},
}
}
}
impl ::std::hash::Hash for $E {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
match *self {
$($E::$V => $by.hash(state),)*
$E::$U(ref s) => s.hash(state),
}
}
}
impl ::std::cmp::Eq for $E {}
)*
}
}
pub mod direct_message;
pub mod entities;
pub mod geometry;
pub mod list;
pub mod place;
pub mod stream;
pub mod tweet;
pub mod user;
pub use self::direct_message::{DirectMessage, DirectMessageId};
pub use self::entities::Entities;
pub use self::geometry::Geometry;
pub use self::list::{List, ListId};
pub use self::place::Place;
pub use self::stream::StreamMessage;
pub use self::tweet::{StatusId, Tweet};
pub use self::user::{User, UserId};
use chrono::{self, DateTime as ChronoDateTime, TimeZone, UTC};
use serde::de::{Deserialize, Deserializer, Error};
string_enums! {
#[derive(Clone, Debug)]
pub enum FilterLevel {
:None("none"),
:Low("low"),
:Medium("medium");
:Custom(_),
}
}
string_enums! {
#[derive(Clone, Debug)]
pub enum WithheldScope {
:Status("status"),
:User("user");
:Custom(_),
}
}
pub type DateTime = ChronoDateTime<UTC>;
impl ::std::default::Default for FilterLevel {
fn default() -> Self {
FilterLevel::None
}
}
fn parse_datetime(s: &str) -> chrono::format::ParseResult<DateTime> {
UTC.datetime_from_str(s, "%a %b %e %H:%M:%S %z %Y")
}
fn deserialize_datetime<D: Deserializer>(d: D) -> Result<DateTime, D::Error> {
parse_datetime(&String::deserialize(d)?).map_err(|e| D::Error::custom(e.to_string()))
}