refactor: make everything a little more modular

This commit is contained in:
VC
2022-04-22 13:36:02 +02:00
parent de375b9f28
commit 080218f385
11 changed files with 478 additions and 323 deletions

38
src/state.rs Normal file
View File

@@ -0,0 +1,38 @@
// auto-imports
use crate::config::Config;
// std
use std::{
fs::{read_to_string, write},
error::Error,
};
// log
use log::debug;
/// Reads last tweet id from a file
pub fn read_state(s: &str) -> Option<u64> {
let state = read_to_string(s);
if let Ok(s) = state {
debug!("Last Tweet ID (from file): {}", &s);
return s.parse::<u64>().ok();
}
None
}
/// Writes last treated tweet id to a file
pub fn write_state(f: &str, s: u64) -> Result<(), std::io::Error> {
write(f, format!("{}", s))
}
/*********
* Main functions
*********/
/// Initiates the DB from path
pub fn init_db(config: &Config) -> Result<(), Box<dyn Error>> {
println!("config.scootaloo.db_path: {}", config.scootaloo.db_path);
Ok(())
}