Created
February 28, 2016 13:20
-
-
Save bjorndown/4f7cb5d9ac8870cb9b37 to your computer and use it in GitHub Desktop.
Rust: Implement fmt::Display for enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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