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