roguelike-game/src/game_log.rs
Timothy Warren 5b8d127af0 Add docs
2022-01-21 15:55:13 -05:00

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());
}
}