crier

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs

commit 9d5b99efba7e36cc16ca4bbaff29ec7ef3a87e9b
parent 441b2fa5b67e739bb654d0f382c33e129f0bdf4f
Author: lash <dev@holbrook.no>
Date:   Mon,  1 Jul 2024 01:42:26 +0100

Create metadata object that can apply itself to feed

Diffstat:
Msrc/lib.rs | 5++++-
Asrc/meta.rs | 28++++++++++++++++++++++++++++
Msrc/tests.rs | 5+----
3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -11,10 +11,11 @@ use atom_syndication::Feed as OutFeed; use std::io::Write; mod meta; mod io; +use meta::FeedMetadata; pub struct Sequencer { - metadata: meta::FeedMetadata, + metadata: FeedMetadata, pub items: HashMap<u64, Vec<u8>>, item_keys: Vec<u64>, crsr: usize, @@ -29,6 +30,7 @@ pub struct SequencerEntry { impl Sequencer { pub fn new() -> Sequencer { Sequencer { + metadata: FeedMetadata::default(), items: HashMap::new(), crsr: 0, limit: 0, @@ -66,6 +68,7 @@ impl Sequencer { feed.set_id("urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6"); feed.set_title("Mixed feed"); feed.set_updated(Local::now().to_utc()); + self.metadata.apply(&mut feed); //feed.write_to(&mut v)?; feed.write_to(w)?; Ok(()) diff --git a/src/meta.rs b/src/meta.rs @@ -0,0 +1,28 @@ +use atom_syndication::Person; +use atom_syndication::Feed; + +pub struct FeedMetadata { + pub author: Person, + complete: bool, +} + +impl Default for FeedMetadata { + fn default() -> FeedMetadata { + FeedMetadata{ + author: Person{ + name: "No One".to_string(), + email: Some("none@devnull.com".to_string()), + uri: Some("https://devnull.com".to_string()), + }, + complete: false, + } + } +} + +impl FeedMetadata { + pub fn apply(&self, feed: &mut Feed) { + let mut persons = Vec::<Person>::new(); + persons.push(self.author.clone()); + feed.set_authors(persons); + } +} diff --git a/src/tests.rs b/src/tests.rs @@ -79,18 +79,15 @@ fn test_feed_mix() { #[test] #[cfg(feature = "fs")] fn test_feed_write() { - let r: Metadata; let fs = Fs{}; let f: NamedTempFile; let fr: File; - let fp: String; let feed = fs.get("testdata/test.atom.xml", None).unwrap(); let mut seq = Sequencer::new(); seq.add_from(feed); f = NamedTempFile::new().unwrap(); fr = f.reopen().unwrap(); - fp = String::from(f.path().to_str().unwrap()); seq.write_to(f).unwrap(); - assert_eq!(fr.metadata().unwrap().len(), 204); + assert_eq!(fr.metadata().unwrap().len(), 301); }