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
pub(crate) mod length_limiter;
use std::fmt::Debug;
use url::Url;
#[derive(Clone, Default)]
pub struct Message {
pub title: Option<String>,
pub body: Option<String>,
pub link: Option<Url>,
pub media: Option<Vec<Media>>,
}
#[derive(Clone, Copy, Debug)]
pub struct MessageId(pub i64);
#[derive(Clone)]
pub enum Media {
Photo(Url),
Video(Url),
}
impl Message {
#[must_use]
pub fn is_empty(&self) -> bool {
self.title.is_none() && self.body.is_none() && self.link.is_none() && self.media.is_none()
}
}
impl From<i64> for MessageId {
fn from(value: i64) -> Self {
Self(value)
}
}
impl Debug for Message {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Message")
.field("title", &self.title)
.field("body", &self.body)
.field("link", &self.link.as_ref().map(Url::as_str))
.field("media", &self.media)
.finish()
}
}
impl Debug for Media {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Photo(x) => f.debug_tuple("Photo").field(&x.as_str()).finish(),
Self::Video(x) => f.debug_tuple("Video").field(&x.as_str()).finish(),
}
}
}