Skip to main content

sitemap_rs/
url_set_error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4/// An error when instantiating or generating sitemaps.
5#[derive(Debug)]
6pub enum UrlSetError {
7    /// Returned when a \<urlset\> contains more than `50,000` \<url\>.
8    TooManyUrls(usize),
9
10    /// Returned when a \<urlset\> contains more than `1,000` \<news\>.
11    TooMuchNews(usize),
12}
13
14impl Error for UrlSetError {}
15
16impl Display for UrlSetError {
17    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18        match self {
19            Self::TooManyUrls(count) => {
20                write!(f, "must not contain more than 50,000 URLs: {count}")
21            }
22            Self::TooMuchNews(count) => {
23                write!(f, "must not contains more than 1,000 news URLs: {count}")
24            }
25        }
26    }
27}