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
mod animation;
mod audio;
mod chat_photo;
mod document;
mod editable_media;
mod group_media;
mod photo;
mod png_sticker;
mod sticker;
mod sticker_for_sticker_set;
mod sticker_set_thumb;
mod tgs_sticker;
mod thumb;
mod video;
mod video_note;
mod voice;
pub(crate) use group_media::Album;
pub use {
animation::Animation, audio::Audio, chat_photo::ChatPhoto,
document::Document, editable_media::EditableMedia, group_media::GroupMedia,
photo::Photo, png_sticker::PngSticker, sticker::Sticker,
sticker_for_sticker_set::StickerForStickerSet,
sticker_set_thumb::StickerSetThumb, tgs_sticker::TgsSticker, thumb::Thumb,
video::Video, video_note::VideoNote, voice::Voice,
};
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub(crate) enum InputFile<'a> {
File { filename: &'a str, bytes: &'a [u8] },
Url(&'a str),
Id(&'a str),
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub(crate) struct WithName<'a> {
pub(crate) file: InputFile<'a>,
pub(crate) name: &'a str,
}
impl<'a> InputFile<'a> {
fn serialize<S>(&self, serializer: S, name: &str) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
InputFile::File { .. } => {
serializer.serialize_str(&format!("attach://{}", name))
}
InputFile::Url(file) | InputFile::Id(file) => {
serializer.serialize_str(file)
}
}
}
const fn with_name(self, name: &'a str) -> WithName<'a> {
WithName { file: self, name }
}
}
impl<'a> serde::Serialize for WithName<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.file.serialize(serializer, self.name)
}
}