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
use crate::types::file;
mod animation;
mod audio;
mod chat_photo;
mod document;
mod editable_media;
mod media_group;
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 media_group::{Album, AnyGroupMedia};
pub use {
animation::Animation,
audio::Audio,
chat_photo::ChatPhoto,
document::Document,
editable_media::EditableMedia,
media_group::{MediaGroup, PhotoOrVideo},
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, Hash)]
pub(crate) enum InputFile {
File { filename: String, bytes: Vec<u8> },
Url(String),
Id(file::Id),
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
struct WithName<'a> {
pub(crate) file: &'a InputFile,
pub(crate) name: &'a str,
}
impl InputFile {
fn serialize<S>(&self, serializer: S, name: &str) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
Self::File { .. } => {
serializer.serialize_str(&format!("attach://{name}"))
}
Self::Url(file) | Self::Id(file::Id(file)) => {
serializer.serialize_str(file)
}
}
}
const fn with_name<'a>(&'a self, name: &'a str) -> WithName<'a> {
WithName { file: self, name }
}
}
impl serde::Serialize for WithName<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.file.serialize(serializer, self.name)
}
}