-
-
Save U007D/ca571a26873dc1cc38d60cbe841c4602 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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(Debug, Clone, Copy)] | |
pub enum CardinalPoint { | |
North = 0x2191, // ↑ | |
NorthEast = 0x2197, // ↗ | |
East = 0x2192, // → | |
SouthEast = 0x2198, // ↘ | |
South = 0x2193, // ↓ | |
SouthWest = 0x2199, // ↙ | |
West = 0x2190, // ← | |
NorthWest = 0x2196, // ↖ | |
} | |
impl fmt::Display for CardinalPoint { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
use std::char; | |
write!(f, "{}", char::from_u32(*self as u32).unwrap()) | |
} | |
} | |
fn main() { | |
println!("{}", CardinalPoint::North); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[16:02] <sebk> pub mod cardinal_point {
[16:02] <sebk> const N: char = '↑',
mklein: sebk +1. the case I raised earlier was a source of undefined behavior, though--your example doesn't suffer from that.