From 1e40e54f17c353314a2dbac9c47cf36daf90b494 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Wed, 2 Sep 2020 17:37:00 -0400 Subject: [PATCH] DB: Pass DBError up naturally --- youmubot-db/src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/youmubot-db/src/lib.rs b/youmubot-db/src/lib.rs index 51c7db6..bbb0b2e 100644 --- a/youmubot-db/src/lib.rs +++ b/youmubot-db/src/lib.rs @@ -1,6 +1,9 @@ -use rustbreak::{deser::Yaml, FileDatabase}; +use rustbreak::{deser::Yaml, FileDatabase, RustbreakError as DBError}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use serenity::{framework::standard::CommandError as Error, model::id::GuildId, prelude::*}; +use serenity::{ + model::id::GuildId, + prelude::{TypeMap, TypeMapKey}, +}; use std::{collections::HashMap, path::Path}; /// GuildMap defines the guild-map type. @@ -12,7 +15,7 @@ pub struct DB(std::marker::PhantomData); /// A short type abbreviation for a FileDatabase. type Database = FileDatabase; -impl serenity::prelude::TypeMapKey for DB { +impl TypeMapKey for DB { type Value = Database; } @@ -21,7 +24,7 @@ where for<'de> T: Deserialize<'de>, { /// Insert into a ShareMap. - pub fn insert_into(data: &mut TypeMap, path: impl AsRef) -> Result<(), Error> { + pub fn insert_into(data: &mut TypeMap, path: impl AsRef) -> Result<(), DBError> { let db = Database::::load_from_path_or_default(path)?; data.insert::>(db); Ok(()) @@ -61,13 +64,11 @@ where T: Send + Sync + Clone + std::fmt::Debug + Serialize + DeserializeOwned, { /// Borrows the FileDatabase. - pub fn borrow(&'a self) -> Result, rustbreak::RustbreakError> { + pub fn borrow(&'a self) -> Result, DBError> { self.db.borrow_data() } /// Borrows the FileDatabase for writing. - pub fn borrow_mut( - &'a mut self, - ) -> Result, rustbreak::RustbreakError> { + pub fn borrow_mut(&'a mut self) -> Result, DBError> { self.needs_save = true; self.db.borrow_data_mut() }