commit 81692c3a1ed22bb853de3ab1fa76664c9967ee6e
parent e72faf913bb968011119f3b65e625e83c395926a
Author: lash <dev@holbrook.no>
Date: Mon, 1 Jul 2024 03:37:19 +0100
Add sequence entry cache write generator
Diffstat:
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -158,6 +158,7 @@ dependencies = [
"rs_sha512",
"rss",
"tempfile",
+ "uuid",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
@@ -20,6 +20,7 @@ rs_sha512 = "^0.1.3"
http = "^1.0"
chrono = "^0.4"
atom_syndication = "^0.12"
+uuid = "^1.9"
[dev-dependencies]
tempfile = "3.3.0"
diff --git a/src/lib.rs b/src/lib.rs
@@ -21,6 +21,10 @@ pub enum Error {
WriteError,
}
+pub trait Cache {
+ fn open(&self, id: String) -> &mut dyn Write;
+ fn close(&self, id: String) -> usize;
+}
pub struct Sequencer<'a> {
metadata: FeedMetadata,
@@ -29,7 +33,7 @@ pub struct Sequencer<'a> {
crsr: usize,
limit: usize,
default_cache: Vec<u8>,
- cache: Option<&'a mut dyn Write>,
+ cache: Option<&'a dyn Cache>,
}
pub struct SequencerEntry {
@@ -55,26 +59,40 @@ impl<'a> Sequencer<'a> {
o
}
- pub fn with_cache(&mut self, w: &'a mut impl Write) -> &Sequencer<'a> {
+ pub fn with_cache(&mut self, w: &'a impl Cache) -> &Sequencer<'a> {
self.cache = Some(w);
return self;
}
pub fn add(&mut self, entry: Entry) -> bool {
+ let have_closer: bool;
let mut w: &mut dyn Write;
+ let mut id: String;
+
+ id = entry.id.to_string();
match &mut self.cache {
Some(v) => {
- w = v;
+ w = v.open(id);
+ have_closer = true;
},
None => {
w = &mut self.default_cache;
},
}
+
+ id = entry.id.to_string();
let o = SequencerEntry::new(entry, w);
if self.items.contains_key(&o.digest) {
return false;
}
self.items.insert(o.digest, o.into());
+ match &mut self.cache {
+ Some(v) => {
+ v.close(id);
+ },
+ None => {
+ },
+ }
return true;
}
diff --git a/src/meta.rs b/src/meta.rs
@@ -1,5 +1,6 @@
use atom_syndication::Person;
use atom_syndication::Feed;
+use uuid::Uuid;
#[derive(Debug)]
pub enum Error {
@@ -10,6 +11,7 @@ pub enum Error {
pub struct FeedMetadata {
pub author: Person,
pub title: String,
+ pub id: String,
incomplete: bool,
}
@@ -22,6 +24,7 @@ impl Default for FeedMetadata {
uri: Some("?".to_string()),
},
title: String::from("?"),
+ id: Uuid::new_v4().to_string(),
incomplete: true,
}
}