parent
bba7fae8b9
commit
47e6cc59c0
7 changed files with 253 additions and 123 deletions
src/post_history
|
@ -1,5 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
|
@ -12,10 +11,13 @@ pub(crate) struct SeriesHistory {
|
|||
}
|
||||
|
||||
impl SeriesHistory {
|
||||
pub(crate) fn load_history() -> Result<Self, Box<dyn Error>> {
|
||||
pub(crate) fn load_history() -> Result<Self, String> {
|
||||
match Path::new("history.toml").exists() {
|
||||
true => {
|
||||
let file_contents: String = fs::read_to_string("history.toml")?;
|
||||
let file_contents: String = match fs::read_to_string("history.toml") {
|
||||
Ok(data) => data,
|
||||
Err(e) => return Err(format!("{}", e)),
|
||||
};
|
||||
|
||||
let history: Result<SeriesHistory, toml::de::Error> = match file_contents.len() {
|
||||
0 => return Ok(SeriesHistory {
|
||||
|
@ -26,7 +28,7 @@ impl SeriesHistory {
|
|||
|
||||
match history {
|
||||
Ok(data) => Ok(data),
|
||||
Err(e) => Err(Box::new(e))
|
||||
Err(e) => Err(format!("{}", e))
|
||||
}
|
||||
},
|
||||
false => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue