libs/userprefs

This commit is contained in:
bunnie 2024-01-14 19:14:08 +08:00
parent c43fd370ee
commit 508476a085

View file

@ -1,8 +1,9 @@
use bincode::error::{DecodeError, EncodeError};
use pddb::Pddb;
use std::io::Read; use std::io::Read;
use std::io::Write; use std::io::Write;
use bincode::error::{DecodeError, EncodeError};
use pddb::Pddb;
static PREFS_DICT: &str = "UserPrefsDict"; static PREFS_DICT: &str = "UserPrefsDict";
// Time-related consts // Time-related consts
@ -20,21 +21,15 @@ pub enum Error {
} }
impl From<std::io::Error> for Error { impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self { fn from(err: std::io::Error) -> Self { Self::IoError(err) }
Self::IoError(err)
}
} }
impl From<EncodeError> for Error { impl From<EncodeError> for Error {
fn from(err: EncodeError) -> Self { fn from(err: EncodeError) -> Self { Self::EncodeError(err) }
Self::EncodeError(err)
}
} }
impl From<DecodeError> for Error { impl From<DecodeError> for Error {
fn from(err: DecodeError) -> Self { fn from(err: DecodeError) -> Self { Self::DecodeError(err) }
Self::DecodeError(err)
}
} }
/// UserPrefs defines the set of all the user preference toggles available for Precursor. /// UserPrefs defines the set of all the user preference toggles available for Precursor.
@ -62,11 +57,7 @@ pub struct Manager {
} }
impl Manager { impl Manager {
pub fn new() -> Self { pub fn new() -> Self { Self { pddb_handle: Pddb::new() } }
Self {
pddb_handle: Pddb::new(),
}
}
fn pddb_store_key(&self, key: &str, value: &[u8]) -> Result<(), Error> { fn pddb_store_key(&self, key: &str, value: &[u8]) -> Result<(), Error> {
match self.pddb_handle.get( match self.pddb_handle.get(
@ -151,7 +142,5 @@ impl Manager {
} }
impl Default for Manager { impl Default for Manager {
fn default() -> Self { fn default() -> Self { Self::new() }
Self::new() }
}
}