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::OrderMode;
|
||||
|
||||
use crate::data::entities::DeckSettings;
|
||||
use rusqlite::Connection;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
|
||||
pub fn load_sets(connection: &Connection) -> Result<Vec<DeckSettings>, NotificationData> {
|
||||
@@ -28,7 +28,7 @@ pub fn load_sets(connection: &Connection) -> Result<Vec<DeckSettings>, Notificat
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub fn add_set(set: &mut DeckSettings, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn add_set(set: &mut DeckSettings, connection: &Connection) -> MaybeError {
|
||||
let index : u32 = connection
|
||||
.query_row(
|
||||
"INSERT INTO card_set (name, forward, backward, filter) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
||||
@@ -46,7 +46,7 @@ pub fn add_set(set: &mut DeckSettings, connection: &Connection) -> Result<(), No
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) -> MaybeError {
|
||||
if !set.id.is_valid() {
|
||||
add_set(set, connection)?;
|
||||
} else {
|
||||
@@ -66,7 +66,7 @@ pub fn update_deck(set: &mut DeckSettings, connection: &Connection) -> Result<()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_set(set: &DeckSettings, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn delete_set(set: &DeckSettings, connection: &Connection) -> MaybeError {
|
||||
if !set.id.is_valid() {
|
||||
return Err(DbSaveError);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user