sitemap_rs/
video_error.rs

1use std::error;
2use std::fmt::{Display, Formatter};
3
4/// An error when instantiating or generating sitemap videos.
5#[derive(Debug)]
6pub enum VideoError {
7    /// Returned when a sitemap video's `description` is longer than `2048` characters.
8    DescriptionTooLong(usize),
9
10    /// Returned when a sitemap video's `duration` is below `1` second.
11    DurationTooShort(u16),
12
13    /// Returned when a sitemap video's `duration` is above `28,800` seconds (`8` hours).
14    DurationTooLong(u16),
15
16    /// Returned when a sitemap video's `rating` is below `0.0`.
17    RatingTooLow(f32),
18
19    /// Returned when a sitemap video's `rating` is above `5.0`.
20    RatingTooHigh(f32),
21
22    /// Returned when a sitemap video's `uploader` `name` is longer than `255` characters.
23    UploaderNameTooLong(usize),
24
25    /// Returned when a sitemap's video element has more than `32` tags.
26    TooManyTags(usize),
27}
28
29impl error::Error for VideoError {}
30
31impl Display for VideoError {
32    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33        match self {
34            Self::DescriptionTooLong(count) => {
35                write!(
36                    f,
37                    "description cannot be longer than 2048 characters: {count}"
38                )
39            }
40            Self::DurationTooShort(duration) => {
41                write!(f, "duration is below 1 (second): {duration}")
42            }
43            Self::DurationTooLong(duration) => {
44                write!(f, "duration is above 28,800 (seconds): {duration}")
45            }
46            Self::RatingTooLow(rating) => {
47                write!(f, "rating is below 0.0: {rating}")
48            }
49            Self::RatingTooHigh(rating) => {
50                write!(f, "rating is above 5.0: {rating}")
51            }
52            Self::UploaderNameTooLong(count) => {
53                write!(f, "uploader name is longer than 255 characters: {count}")
54            }
55            Self::TooManyTags(count) => {
56                write!(f, "must not have more than 32 tags: {count}")
57            }
58        }
59    }
60}