-
-
Save iamjarvo/ddda3889820811c50f2d945098ccd37a 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