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
macro_rules! message_base {
(
struct $name:ident {
$(#[doc = $field_doc:literal] $field:ident: $type:ty,)*
} -> EventLoop::$handler:ident
fn new(
$($param:ident: $param_type:ty,)*
) -> Self {
$(infer $infer:ident;)*
Self {
$($new_field:ident: $value:expr,)*
}
}
) => {
common! {
#[doc = concat!(
"The context for [`", stringify!($handler), "`][handler] ",
"handlers.\n\n",
"[handler]: crate::EventLoop::", stringify!($handler),
)]
struct $name {
message_id: crate::types::message::Id,
from: Option<crate::types::message::From>,
date: i64,
chat: crate::types::Chat,
$(#[doc = $field_doc] $field: $type,)*
}
}
impl $name {
#[allow(clippy::redundant_field_names, clippy::missing_const_for_fn)]
pub(crate) fn new(
bot: crate::Bot,
data: crate::types::message::Data,
$($param: $param_type,)*
) -> Self {
Self {
bot,
message_id: data.id,
from: data.from,
date: data.date,
chat: data.chat,
$($new_field: $value,)*
$($infer: data.$infer,)*
}
}
}
impl crate::contexts::fields::Message for $name {
#[must_use]
fn message_id(&self) -> crate::types::message::Id {
self.message_id
}
#[must_use]
fn from(&self) -> Option<&crate::types::message::From> {
self.from.as_ref()
}
#[must_use]
fn date(&self) -> i64 {
self.date
}
#[must_use]
fn chat(&self) -> &crate::types::Chat {
&self.chat
}
}
}
}