Introduce MaybeError type
This commit is contained in:
1 parent
d836b57d2a
commit
a60ed37cd4
16 files changed
+127
-93
No files matched your search
@@ -2,7 +2,7 @@ use crate::core::srs::WordOpenMode;
|
||||
use crate::data::Id;
|
||||
use crate::data::entities::HistoryItem;
|
||||
use crate::fs::*;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
use chrono::DateTime;
|
||||
use std::fs::{File, OpenOptions};
|
||||
@@ -20,7 +20,7 @@ pub fn get_history_of_set(id: Id) -> Result<Vec<HistoryItem>, NotificationData>
|
||||
Ok(parse_history_items(lines))
|
||||
}
|
||||
|
||||
fn append_lines_if_exists(path: PathBuf, lines: &mut Vec<String>) -> Result<(), NotificationData> {
|
||||
fn append_lines_if_exists(path: PathBuf, lines: &mut Vec<String>) -> MaybeError {
|
||||
if path.exists() {
|
||||
let reader = BufReader::new(File::open(path).map_err(|_| PermissionDenied)?);
|
||||
reader
|
||||
@@ -63,7 +63,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
||||
items
|
||||
}
|
||||
|
||||
pub fn push_note(set_id: Id, item: HistoryItem) -> Result<(), NotificationData> {
|
||||
pub fn push_note(set_id: Id, item: HistoryItem) -> MaybeError {
|
||||
let app_dir = history_dir()?;
|
||||
let path = app_dir.clone().join(format!("set_{}_history.csv", set_id));
|
||||
|
||||
|
||||
Reference in new issue
Block a user