crier

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

commit 29e13c50a6bb061a89b920ea54929097f6809170
parent e3a598dda667bb2c0580c54c11139786981e7f17
Author: lash <dev@holbrook.no>
Date:   Sat,  6 Jul 2024 17:02:29 +0100

Move cache trait definition to separate file

Diffstat:
Asrc/cache.rs | 7+++++++
Msrc/io/fs.rs | 11+++++++++--
Msrc/lib.rs | 3++-
Msrc/mem.rs | 6++----
Msrc/tests.rs | 33++++++++++++++++++++++++++++-----
5 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/src/cache.rs b/src/cache.rs @@ -0,0 +1,7 @@ +use std::io::Write; + + +pub trait Cache { + fn open(&mut self, id: String) -> &mut dyn Write; + fn close(&mut self, id: String) -> usize; +} diff --git a/src/io/fs.rs b/src/io/fs.rs @@ -8,10 +8,13 @@ use std::fs::File; //use core::str::FromStr; //use std::io::stderr; -pub struct Fs { +use crate::cache::Cache; + + +pub struct FsFeed { } -impl FeedGet for Fs { +impl FeedGet for FsFeed { fn get(&self, s: &str, _method: Option<FeedMethod>) -> Result<Feed, u64> { //let uri = Uri::from_str(s).unwrap(); let f = File::open(s).unwrap(); @@ -19,3 +22,7 @@ impl FeedGet for Fs { Ok(feed) } } + +//impl Cache for FsCache { + +//} diff --git a/src/lib.rs b/src/lib.rs @@ -15,10 +15,11 @@ use atom_syndication::Feed as OutFeed; mod meta; mod io; mod mem; +mod cache; use meta::FeedMetadata; //use mem::MemCache; use mem::CacheWriter; -use mem::Cache; +use cache::Cache; #[derive(Debug)] pub enum Error { diff --git a/src/mem.rs b/src/mem.rs @@ -2,10 +2,8 @@ use std::collections::HashMap; use std::io::Write; use std::io::Error; -pub trait Cache { - fn open(&mut self, id: String) -> &mut dyn Write; - fn close(&mut self, id: String) -> usize; -} +use crate::cache::Cache; + pub struct CacheWriter { data: Vec<u8>, diff --git a/src/tests.rs b/src/tests.rs @@ -9,7 +9,7 @@ use super::Sequencer; use super::io::FeedGet; #[cfg(feature = "fs")] -use super::io::fs::Fs; +use crate::io::fs::FsFeed; #[test] @@ -40,7 +40,7 @@ fn test_entry_guard() { #[cfg(feature = "fs")] fn test_feed_get() { let r: bool; - let fs = Fs{}; + let fs = FsFeed{}; let feed = fs.get("testdata/test.atom.xml", None).unwrap(); let mut seq = Sequencer::new(); r = seq.add(feed.entries.get(0).unwrap().clone()); @@ -51,7 +51,7 @@ fn test_feed_get() { #[cfg(feature = "fs")] fn test_feed_all() { let r: i64; - let fs = Fs{}; + let fs = FsFeed{}; let feed = fs.get("testdata/test.atom.xml", None).unwrap(); let mut seq = Sequencer::new(); r = seq.add_from(feed); @@ -62,7 +62,7 @@ fn test_feed_all() { #[cfg(feature = "fs")] fn test_feed_mix() { let mut r: i64; - let fs = Fs{}; + let fs = FsFeed{}; let mut feed = fs.get("testdata/test.atom.xml", None).unwrap(); let mut seq = Sequencer::new(); r = seq.add_from(feed); @@ -78,7 +78,7 @@ fn test_feed_mix() { #[cfg(feature = "fs")] fn test_feed_write() { let r: usize; - let fs = Fs{}; + let fs = FsFeed{}; let f: NamedTempFile; let fr: File; @@ -91,3 +91,26 @@ fn test_feed_write() { assert_eq!(r, 15); assert_eq!(fr.metadata().unwrap().len(), 254); } + +//#[test] +//#[cfg(feature = "fs")] +//fn test_feed_write_extcache() { +// let r: usize; +// let fs = FsFeed{}; +// let mut f: NamedTempFile; +// let fw: File; +// let fr: File; +// +// f = NamedTempFile::new().unwrap(); +// fw = f.reopen().unwrap(); +// +// let feed = fs.get("testdata/test.atom.xml", None).unwrap(); +// let mut seq = Sequencer::new().with_cache(&mut fw); +// +// seq.add_from(feed); +// f = NamedTempFile::new().unwrap(); +// fr = f.reopen().unwrap(); +// r = seq.write_to(f).unwrap(); +// assert_eq!(r, 15); +// assert_eq!(fr.metadata().unwrap().len(), 254); +//}