HighScoreManager

Struct HighScoreManager 

Source
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() and db.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: Db

Implementations§

Source§

impl HighScoreManager

Source

pub fn new() -> Result<Self, Error>

§Errors

If DB reads / writes issues

Source

pub fn new_with_custom_path<P: AsRef<Path>>(path: P) -> Result<Self, Error>

§Errors

If DB reads / writes issues

Source

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

Source

pub fn shrink_db(&self) -> Result<(), Box<dyn Error>>

Shrink the DB to MAX_SCORE_ENTRIES size

§Errors

If DB reads / writes issues

Source

pub fn get_top_scores(&self) -> Vec<HighScore>

Source

pub fn get_rank( &self, player_score_value: u32, ) -> Result<Option<usize>, Box<dyn Error>>

Get the rank of the score submitted among the MAX_SCORE_ENTRIES Use the Sled lexicographic order to have it free

§Errors

If DB reads / writes issues

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V