meta.rs (1449B)
1 use atom_syndication::Person; 2 use atom_syndication::Feed; 3 use uuid::Uuid; 4 5 #[derive(Debug)] 6 pub enum Error { 7 IncompleteFeedMetadata, 8 } 9 10 11 pub struct FeedMetadata { 12 pub author: Person, 13 pub title: String, 14 pub id: String, 15 flag: u8, 16 } 17 18 impl Default for FeedMetadata { 19 fn default() -> FeedMetadata { 20 FeedMetadata{ 21 author: Person{ 22 name: "?".to_string(), 23 email: Some("?".to_string()), 24 uri: Some("?".to_string()), 25 }, 26 title: String::from("?"), 27 id: Uuid::new_v4().to_string(), 28 flag: 0, 29 } 30 } 31 32 33 } 34 35 impl FeedMetadata { 36 pub fn force(&mut self) { 37 self.flag |= 3; 38 } 39 40 fn check_complete(&self) -> bool { 41 self.flag >= 3 42 } 43 44 pub fn set_author(&mut self, author: Person) -> bool { 45 self.author = author; 46 self.flag |= 1; 47 self.check_complete() 48 } 49 50 51 pub fn set_title(&mut self, title: String) -> bool { 52 self.title = title; 53 self.flag |= 2; 54 self.check_complete() 55 } 56 57 pub fn apply(&self, feed: &mut Feed) -> Result<(), Error> { 58 if !self.check_complete() { 59 return Err(Error::IncompleteFeedMetadata); 60 } 61 let mut persons = Vec::<Person>::new(); 62 persons.push(self.author.clone()); 63 feed.set_authors(persons); 64 feed.set_title(self.title.clone()); 65 Ok(()) 66 } 67 }