Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. macro_rules! enum_to_primitive {
  2. ($name:ident) => {
  3. impl ToPrimitive for $name {
  4. fn to_i64(&self) -> Option<i64> {
  5. return Some(*self as i64);
  6. }
  7.  
  8. fn to_u64(&self) -> Option<u64> {
  9. return Some(*self as u64);
  10. }
  11. }
  12. }
  13. }
  14.  
  15. macro_rules! enum_primitive {
  16. (
  17. $(#[$mt:meta])*
  18. pub enum $name:ident {
  19. $($field:tt)*
  20. }
  21. ) =>
  22. {
  23. enum_from_primitive! {
  24. $(#[$mt])*
  25. #[derive(Debug,Clone,Copy)]
  26. pub enum $name {
  27. $($field)*
  28. }
  29. }
  30. enum_to_primitive!($name);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement