1
0
Fork 0
roguelike-game/src/game_log.rs

25 lines
691 B
Rust

/// A struct to hold the player's game log.
#[derive(Default)]
pub struct GameLog {
pub entries: Vec<String>,
}
impl GameLog {
/// Convenience constructor that adds the first
/// entry to the game log.
pub fn new<S: ToString>(first_entry: S) -> Self {
let mut log = GameLog::default();
log.append(first_entry);
log
}
/// Convenience method for adding an entry to the game log.
/// Generic on the [`ToString`] trait so that [`&str`], [`String`],
/// and `&String` types, all work without more type juggling
/// at the call site.
pub fn append<S: ToString>(&mut self, s: S) {
self.entries.push(s.to_string());
}
}