Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. extern crate syn;
  2. #[macro_use] extern crate quote;
  3. extern crate proc_macro2;
  4.  
  5. use proc_macro2::Span;
  6.  
  7. fn main() {
  8. let name = syn::Ident::new("Point", Span::call_site());
  9. let fields: Vec<_> = vec!["x", "y"]
  10. .into_iter()
  11. .map(|s| syn::Ident::new(s, Span::call_site()))
  12. .collect();
  13.  
  14. let values = 0..fields.len();
  15.  
  16. let tok = quote! {
  17. struct #name {
  18. #( #fields: #values ),*
  19. }
  20. };
  21.  
  22. println!("{}", tok)
  23. }
Add Comment
Please, Sign In to add comment