Created
September 29, 2016 15:59
-
-
Save chrivers/b0812a5b6574307139d0fff3f20ea26c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
macro_rules! enum_to_primitive { | |
($name:ident) => { | |
impl ToPrimitive for $name { | |
fn to_i64(&self) -> Option<i64> { | |
return Some(*self as i64); | |
} | |
fn to_u64(&self) -> Option<u64> { | |
return Some(*self as u64); | |
} | |
} | |
} | |
} | |
macro_rules! enum_primitive { | |
( | |
$(#[$mt:meta])* | |
pub enum $name:ident { | |
$($field:tt)* | |
} | |
) => | |
{ | |
enum_from_primitive! { | |
$(#[$mt])* | |
#[derive(Debug,Clone,Copy)] | |
pub enum $name { | |
$($field)* | |
} | |
} | |
enum_to_primitive!($name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment