Skip to content

Instantly share code, notes, and snippets.

@bjorndown
Created February 28, 2016 13:20
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bjorndown/4f7cb5d9ac8870cb9b37 to your computer and use it in GitHub Desktop.
Save bjorndown/4f7cb5d9ac8870cb9b37 to your computer and use it in GitHub Desktop.
Rust: Implement fmt::Display for enum
use std::fmt;
#[derive(Copy,Clone)]
enum CellState { Dead, Alive }
impl fmt::Display for CellState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let printable = match *self {
CellState::Alive => 'x',
CellState::Dead => ' ',
};
write!(f, "{}", printable)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment