pub struct HighScoreManager {
db: Db,
}Expand description
§Motivation for this DB
To use something else than SQL DB to change ;) Top-edge DB For a more rock solid DB in Rust use redb (more typed (no manuel BE management), more stable, less innovant)
§Strengths
- Sled database guarantees that its iterators, including those returned by
db.iter()anddb.range(), will return elements in lexicographical order of their keys. (as raw byte slices) - This is a fundamental feature of sled because it is built upon a $\text{Bw-Tree}$ structure, which is a type of ordered, persistent tree.
- The sorting is strictly lexicographical; you must ensure that multibyte numeric keys are stored in Big-Endian byte order.
- Big-Endian (BE): Stores the Most Significant Byte (MSB) first. This is required for correct lexicographical sorting of numbers.
§To explore the DB content by hands:
- cargo install sledcli (or use EDMA)
- hex or str to change the view
- Pairs or keys
§Why TOML serialisation
- Provide a better visualization by hands
- Not too much data, TOML overhead is unseen
- Already used for arguments serialisation, avoid a new dependency (and the bincode crate story is a lesson-teller)
- NB: on other projects with others constrains postcard,rkyv,or borsh
Fields§
§db: DbImplementations§
Source§impl HighScoreManager
impl HighScoreManager
Sourcepub fn new_with_custom_path<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub fn new_with_custom_path<P: AsRef<Path>>(path: P) -> Result<Self, Error>
§Errors
If DB reads / writes issues
Sourcepub fn save_score(&self, score: &HighScore) -> Result<(), Box<dyn Error>>
pub fn save_score(&self, score: &HighScore) -> Result<(), Box<dyn Error>>
Save score in the DB and then shrink the DB to MAX_SCORE_ENTRIES
if score is not in the best MAX_SCORE_ENTRIES, it will not be inserted
§Errors
If DB reads / writes issues
pub fn get_top_scores(&self) -> Vec<HighScore>
Auto Trait Implementations§
impl Freeze for HighScoreManager
impl !RefUnwindSafe for HighScoreManager
impl Send for HighScoreManager
impl Sync for HighScoreManager
impl Unpin for HighScoreManager
impl !UnwindSafe for HighScoreManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more