Skip to content

Instantly share code, notes, and snippets.

@U007D
Forked from anonymous/playground.rs
Created February 14, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save U007D/ca571a26873dc1cc38d60cbe841c4602 to your computer and use it in GitHub Desktop.
Save U007D/ca571a26873dc1cc38d60cbe841c4602 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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);
}
@U007D
Copy link
Author

U007D commented Feb 14, 2018

[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment