Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. macro_rules! expand {
  2. (
  3. $(#[cb $attr:meta])*
  4. $(#[$attr:meta])*
  5. pub fn foo() {}
  6. ) => (
  7. expand_attrs! {
  8. [ $($attr),* ]
  9. $(#[$attr])*
  10. pub fn foo() {}
  11. }
  12. );
  13. }
  14.  
  15. macro_rules! expand_attrs {
  16. (
  17. [ ]
  18. $($rest:tt)*
  19. ) => ($($rest)*);
  20.  
  21. (
  22. [
  23. foo
  24. $($rest:meta)*
  25. ]
  26. $($body:tt)*
  27. ) => (
  28. expand_attrs! {
  29. [ $($rest)* ]
  30. $($body)*
  31. }
  32. )
  33.  
  34. (
  35. [
  36. bar($a:meta)
  37. $($rest:meta)*
  38. ]
  39. $($body:tt)*
  40. ) => (
  41. expand_attrs! {
  42. [ $($rest)* ]
  43. $($body)*
  44. }
  45. )
  46. }
  47.  
  48. expand! {
  49. #[foo]
  50. #[bar(a)]
  51. pub fn foo() {}
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement