#[derive(Debug)] pub struct HighScores<'a> { scores: &'a [u32] } impl<'a> HighScores<'a> { pub fn new(scores: &'a [u32]) -> Self { HighScores{ scores } } pub fn scores(&self) -> &[u32] { self.scores } pub fn latest(&self) -> Option { self.scores.last().copied() } pub fn personal_best(&self) -> Option { self.scores.iter().max().copied() } pub fn personal_top_three(&self) -> Vec { let mut top3 = self.scores.to_vec(); top3.sort_unstable_by(|a,b| b.cmp(a)); top3.truncate(3); top3 } }