crier

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

commit 4ddc2ceee94de5df966a6c77103aa845b6a0e257
parent 8203a612910a1879d052abc0104fb5aa72cfac0d
Author: lash <dev@holbrook.no>
Date:   Sun, 30 Jun 2024 22:58:23 +0100

Create add all option for sequencer

Diffstat:
Msrc/lib.rs | 29+++++++++++++++++++++++++++++
Msrc/tests.rs | 11+++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -3,6 +3,7 @@ use std::hash::Hasher; use std::hash::Hash; use std::iter::Iterator; use feed_rs::model::Entry; +use feed_rs::model::Feed; use rs_sha512::Sha512Hasher; use chrono::DateTime; mod io; @@ -35,6 +36,17 @@ impl Sequencer { self.items.insert(o.digest, o.into()); return true; } + + pub fn add_all(&mut self, feed: Feed) -> i64 { + let mut c: i64; + + c = 0; + for v in feed.entries.iter() { + self.add(v.clone()); + c += 1; + } + c + } } impl Iterator for Sequencer { @@ -50,20 +62,37 @@ impl Iterator for Sequencer { impl SequencerEntry { pub fn new(entry: Entry) -> SequencerEntry { + let mut have_date: bool; let mut id_part: u32; let mut o = SequencerEntry { entry: entry, digest: 0, }; + + have_date = false; match &o.entry.published { Some(v) => { id_part = v.timestamp() as u32; o.digest = id_part as u64; o.digest <<= 32; + have_date = true; }, None => { }, } + + if !have_date { + match &o.entry.updated { + Some(v) => { + id_part = v.timestamp() as u32; + o.digest = id_part as u64; + o.digest <<= 32; + have_date = true; + }, + None => { + }, + } + } let mut h = Sha512Hasher::default(); o.hash(&mut h); diff --git a/src/tests.rs b/src/tests.rs @@ -41,3 +41,14 @@ fn test_feed_get() { r = seq.add(feed.entries.get(0).unwrap().clone()); assert!(r); } + +#[test] +#[cfg(feature = "fs")] +fn test_feed_all() { + let r: i64; + let fs = Fs{}; + let feed = fs.get("testdata/test.atom.xml", None).unwrap(); + let mut seq = Sequencer::new(); + r = seq.add_all(feed); + assert_eq!(r, 15); +}