From 95ed1735e77b8dfe01e48b5864496142fe2217b9 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 29 Jul 2023 19:59:16 +0100 Subject: [PATCH] remove FeedEnv --- src/feed/mod.rs | 6 ------ src/fetch.rs | 3 +-- src/history/add.rs | 3 ++- src/history/find.rs | 3 ++- src/history/mod.rs | 12 +----------- src/lib.rs | 10 +++------- src/main.rs | 10 +--------- 7 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/feed/mod.rs b/src/feed/mod.rs index d8c68d0..c3486dc 100644 --- a/src/feed/mod.rs +++ b/src/feed/mod.rs @@ -7,12 +7,6 @@ mod find; pub use find::find; -pub struct FeedEnv { - pub find: FeedFind, -} - -pub type FeedFind = fn(&str, &str, &NetworkEnv) -> Result; - pub fn get(url: &str, e: &NetworkEnv) -> Result { let content = (e.fetch_as_bytes)(url)?; let channel = Feed::read_from(&content[..])?; diff --git a/src/fetch.rs b/src/fetch.rs index cad48b0..e34dea4 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -1,6 +1,5 @@ -use crate::prelude::*; +use crate::{history::Link, prelude::*}; -use atom_syndication::Link; use std::process::Command; pub struct FetchEnv { diff --git a/src/history/add.rs b/src/history/add.rs index 756edf2..580c219 100644 --- a/src/history/add.rs +++ b/src/history/add.rs @@ -1,9 +1,10 @@ use crate::prelude::*; -use atom_syndication::Link; use std::fs::OpenOptions; use std::io::prelude::*; +use super::Link; + pub fn add(link: &Link, file_name: &str) -> Result<()> { let mut file = OpenOptions::new() .write(true) diff --git a/src/history/find.rs b/src/history/find.rs index 70162d2..bb6cdc2 100644 --- a/src/history/find.rs +++ b/src/history/find.rs @@ -1,8 +1,9 @@ use crate::{file::FileEnv, prelude::*}; -use atom_syndication::Link; use std::io::{BufRead, BufReader}; +use super::Link; + pub fn find(link: &Link, file_name: &str, e: &FileEnv) -> Result { if let Ok(file) = (e.open)(file_name) { let reader = BufReader::new(file); diff --git a/src/history/mod.rs b/src/history/mod.rs index 47f7e36..a658069 100644 --- a/src/history/mod.rs +++ b/src/history/mod.rs @@ -1,17 +1,7 @@ -use crate::{file::FileEnv, prelude::*}; - mod add; mod find; pub use add::add; pub use find::find; -type Link = atom_syndication::Link; - -pub struct HistoryEnv { - pub find: HistoryFind, - pub add: HistoryAdd, -} - -pub type HistoryFind = fn(&Link, &str, &FileEnv) -> Result; -pub type HistoryAdd = fn(&Link, &str) -> Result<()>; +pub type Link = atom_syndication::Link; diff --git a/src/lib.rs b/src/lib.rs index 9137f13..57fab72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,17 +9,13 @@ pub mod prelude; #[cfg(test)] mod test_utils; -use feed::FeedEnv; use fetch::FetchEnv; use file::FileEnv; -use history::HistoryEnv; use network::NetworkEnv; use prelude::*; pub struct Env { - pub feed: FeedEnv, pub network: NetworkEnv, - pub history: HistoryEnv, pub fetch: FetchEnv, pub file: FileEnv, } @@ -27,13 +23,13 @@ pub struct Env { pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> { for channel_name in file::read::lines_from(subscriptions, &e.file)? { println!("Channel: {}", channel_name); - let feed_url = (e.feed.find)(site, &channel_name, &e.network)?; + let feed_url = feed::find(site, &channel_name, &e.network)?; for entry in feed::get(&feed_url, &e.network)?.entries() { if let Some(link) = entry.links().get(0).cloned() { - if !(e.history.find)(&link, history, &e.file)? { + if !history::find(&link, history, &e.file)? { println!("Downloading {}: {}", &channel_name, entry.title().as_str()); (e.fetch.download)(&link)?; - (e.history.add)(&link, history)?; + history::add(&link, history)?; } } } diff --git a/src/main.rs b/src/main.rs index 395e811..83d2966 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use podal::file::FileEnv; use podal::network::NetworkEnv; use podal::prelude::*; -use podal::{feed::FeedEnv, fetch::FetchEnv, history::HistoryEnv}; +use podal::fetch::FetchEnv; fn main() -> Result<()> { println!("Podal"); @@ -15,14 +15,6 @@ fn main() -> Result<()> { history, site, podal::Env { - feed: FeedEnv { - find: podal::feed::find, - }, - - history: HistoryEnv { - find: podal::history::find, - add: podal::history::add, - }, fetch: FetchEnv { download: podal::fetch::download, },