use time::OffsetDateTime; use url::Url; /// Represents a single record in the XML sitemap index. /// /// ```rust /// use time::macros::datetime; /// use url::Url; /// use sitemapo::record::IndexRecord; /// /// let _ = IndexRecord::new(Url::parse("https://example.com/").unwrap()) /// .with_modified(datetime!(2020-01-01 0:00 UTC)); /// ``` #[derive(Debug, Clone)] pub struct IndexRecord { pub(crate) location: Option, pub(crate) modified: Option, } impl IndexRecord { /// Creates a new instance with a provided location. pub fn new(location: Url) -> Self { Self { location: Some(location), modified: None, } } /// Creates a new instance with no location. pub(crate) fn clean() -> Self { Self { location: None, modified: None, } } /// pub fn with_modified(self, modified: OffsetDateTime) -> Self { Self { modified: Some(modified), ..self } } /// pub fn location(&self) -> &Url { self.location .as_ref() .expect("should be properly initialized") } /// pub fn modified(&self) -> &Option { &self.modified } } impl From for IndexRecord { fn from(location: Url) -> Self { IndexRecord::new(location) } }