Skip to main content

format_stats

Function format_stats 

Source
pub fn format_stats(completion: &LevelCompletion) -> String
Expand description

The statistics line of the success panel: Čas: 12s | Nápovědy: 1 | Chybné pokusy: 2. Failed attempts are mentioned only when there were any.

use chrono::NaiveDate;
use shellgame::state::LevelCompletion;
use shellgame::ui::screens::format_stats;

let completed_at = NaiveDate::from_ymd_opt(2026, 1, 2).unwrap().and_hms_opt(3, 4, 5).unwrap();
let clean = LevelCompletion { time_sec: 12, hints: 0, attempts: 0, completed_at };
assert_eq!(format_stats(&clean), "Čas: 12s  |  Nápovědy: 0");
let messy = LevelCompletion { attempts: 2, ..clean };
assert_eq!(format_stats(&messy), "Čas: 12s  |  Nápovědy: 0  |  Chybné pokusy: 2");