Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. macro_rules! anonymous {
  2. {
  3. $($field_name:ident : $field_expr:expr),+
  4. } => {
  5. {
  6. #[allow(non_camel_case_types)]
  7. #[derive(Debug)] // Can add more derives here if wanted
  8. struct r#struct<$($field_name),+> {
  9. $($field_name: $field_name),+
  10. }
  11.  
  12. r#struct {
  13. $($field_name: $field_expr),+
  14. }
  15. }
  16. };
  17. {
  18. $($field_name:ident : $field_expr:expr),+,
  19. } => {
  20. anonymous! { $($field_name : $field_expr),+ }
  21. }
  22. }
  23. struct r#struct {
  24. z: u32
  25. }
  26. fn main() {
  27.  
  28. let y = anonymous! { x: r#struct { z: 0u32 } };
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement