pub struct RecordBook { /* private fields */ }Implementations§
Source§impl RecordBook
impl RecordBook
Sourcepub fn entries(&self) -> &[Record]
pub fn entries(&self) -> &[Record]
Entries in insertion order, which is also their serialized index order.
Sourcepub fn ordered_entries(&self) -> Vec<&Record>
pub fn ordered_entries(&self) -> Vec<&Record>
A view ordered lexicographically by ID, then by ascending numeric context.
Allocates at most MAX_RECORDS references. Does not reorder the book or
its serialized entries; score/time ties do not affect identity ordering.
use ferravex_play::persistence::RecordBook;
let mut book = RecordBook::default();
book.record("z-course", 1, 10, None)?;
book.record("a-course", 2, 10, None)?;
book.record("a-course", 1, 10, None)?;
let keys: Vec<_> = book.ordered_entries().into_iter()
.map(|record| (record.id.as_str(), record.context)).collect();
assert_eq!(keys, [("a-course", 1), ("a-course", 2), ("z-course", 1)]);
assert_eq!(book.entries()[0].id, "z-course");pub fn get(&self, id: &str, context: u64) -> Option<&Record>
Sourcepub fn record(
&mut self,
id: &str,
context: u64,
score: u64,
time_us: Option<u64>,
) -> Result<(), SaveError>
pub fn record( &mut self, id: &str, context: u64, score: u64, time_us: Option<u64>, ) -> Result<(), SaveError>
Record one completed attempt. Only supply time for a successful finish. Score/time maxima and context identity never pass through floating point.
Sourcepub fn compare(
&self,
id: &str,
context: u64,
score: u64,
time_us: Option<u64>,
) -> Result<RecordSummary, SaveError>
pub fn compare( &self, id: &str, context: u64, score: u64, time_us: Option<u64>, ) -> Result<RecordSummary, SaveError>
Preview an attempt against the current bests without mutation or allocation.
Uses exactly the acceptance checks of Self::record: malformed IDs and
zero/out-of-range times return SaveError::InvalidData; a new identity
in a full book or an overflowing run count returns SaveError::Capacity.
A full book can still accept attempts for an existing identity. None
supplies no successful time; the score and attempt count still apply.
A preview does not reserve an attempt. Use Self::record_with_summary
to emit feedback from the summary of an actually accepted attempt.
use ferravex_play::persistence::RecordBook;
let mut book = RecordBook::default();
book.record("course", 1, 100, Some(2_000_000))?;
let preview = book.compare("course", 1, 90, Some(1_500_000))?;
assert_eq!(preview.score.delta, Some(-10));
assert!(!preview.score.comparison.is_new_best());
assert_eq!(preview.time_us.unwrap().delta, Some(-500_000));
assert!(preview.time_us.unwrap().comparison.is_new_best());
assert_eq!(preview.runs, 2);
assert_eq!(book.get("course", 1).unwrap().runs, 1);Sourcepub fn record_with_summary(
&mut self,
id: &str,
context: u64,
score: u64,
time_us: Option<u64>,
) -> Result<RecordSummary, SaveError>
pub fn record_with_summary( &mut self, id: &str, context: u64, score: u64, time_us: Option<u64>, ) -> Result<RecordSummary, SaveError>
Accept one attempt and return its comparisons against the previous bests.
Uses the same validation and independent best updates as Self::record.
All checks finish before mutation: errors leave the entire book unchanged.
Ties and worse runs are accepted and increment runs without replacing
their respective bests. Summary calculation allocates no storage; a new
identity retains the existing bounded entry/ID allocation behavior.
use ferravex_play::persistence::RecordBook;
let mut book = RecordBook::default();
let first = book.record_with_summary("course", 1, 0, None)?;
assert!(first.score.comparison.is_new_best());
assert_eq!(first.score.delta, None);
let next = book.record_with_summary("course", 1, u64::MAX, Some(1))?;
assert_eq!(next.score.delta, Some(i128::from(u64::MAX)));
assert_eq!(next.time_us.unwrap().previous, None);
assert_eq!(book.get("course", 1).unwrap().runs, 2);Trait Implementations§
Source§impl Clone for RecordBook
impl Clone for RecordBook
Source§fn clone(&self) -> RecordBook
fn clone(&self) -> RecordBook
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more