pub trait Tile {
// Required method
fn tile(&self) -> StyledContent<&'static str>;
}
Expand description
Tile
allows to represent any other data type as tile
,
or more specifically as StyledContent<&'static str>
§Examples
use cli_tilemap::Tile;
use crossterm::style::{Stylize, StyledContent};
#[derive(Default, Debug)]
enum Entity {
Enemy,
Hero,
#[default]
Air,
}
impl Tile for Entity {
fn tile(&self) -> StyledContent<&'static str> {
match self {
Self::Air => "[-]".dark_grey().bold(),
Self::Hero => "[&]".green().bold(),
Self::Enemy => "[@]".red().bold(),
}
}
}
let hero = Entity::Hero;
assert_eq!(hero.tile(), "[&]".green().bold());