Skip to main content

rsynko_x/
bundle.rs

1use crate::AttachmentKind;
2use alux_sdk::case_mapping;
3
4/// Selects which of the files a tweet carries are taken from it.
5///
6/// A tweet is a bundle, so what to take is a choice like any other: a reader picks one of these,
7/// or picks one file out of the bundle by name. Each of these names what it *does* — not what it
8/// is for — and states exactly which kinds it accepts.
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum Take {
11    /// Takes every file the tweet carries.
12    Everything,
13    /// Takes the videos and animations, and leaves the pictures.
14    Videos,
15    /// Takes the pictures, and leaves the videos.
16    Images,
17}
18
19case_mapping! {
20    Take, &'static str as &str,
21        Everything <=> "everything",
22        Videos     <=> "video",
23        Images     <=> "images",
24}
25
26impl Take {
27    /// States what taking this way does, and then what that is usually wanted for.
28    ///
29    /// A reader chooses by what a way of taking does, and confirms the choice by what it is good
30    /// for, so both are stated and in that order.
31    #[must_use]
32    pub const fn summary(self) -> &'static str {
33        match self {
34            Self::Everything => "takes every file the tweet carries, good for keeping the whole post",
35            Self::Videos => "takes the videos only, good for clips",
36            Self::Images => "takes the pictures only, good for photographs",
37        }
38    }
39
40    /// States whether taking this way accepts one kind of file.
41    #[must_use]
42    pub const fn accepts(self, kind: AttachmentKind) -> bool {
43        match self {
44            Self::Everything => true,
45            // An animation is a video that was posted as a picture, and is fetched as a video.
46            Self::Videos => matches!(kind, AttachmentKind::Video | AttachmentKind::Animation),
47            Self::Images => matches!(kind, AttachmentKind::Photo),
48        }
49    }
50}