From 5dd76b7e68c7c5a185d076125d185209206be7d5 Mon Sep 17 00:00:00 2001 From: Tyler Tracey Date: Sun, 4 Nov 2018 21:20:10 -0500 Subject: [PATCH] Proc attribute integer literals... Hello! I ran into this issue when following along with the tutorials. Firstly they are amazing and truly helpful in the GL space. I've really loved them. So thank you. My guess is that this is due to a change in rustc since the tutorials were posted. Basically this is a simple change to support integer literals on top of string literals in the procedural macro attributes. --- lesson-10/render_gl_derive/src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lesson-10/render_gl_derive/src/lib.rs b/lesson-10/render_gl_derive/src/lib.rs index d3f3e23..88c0fd3 100644 --- a/lesson-10/render_gl_derive/src/lib.rs +++ b/lesson-10/render_gl_derive/src/lib.rs @@ -56,11 +56,20 @@ fn generate_struct_field_vertex_attrib_pointer_call(field: &syn::Field) -> quote )); let location_value: usize = match location_attr.value { - syn::MetaItem::NameValue(_, syn::Lit::Str(ref s, _)) => s.parse() - .unwrap_or_else( - |_| panic!("Field {} location attribute value must contain an integer", field_name) - ), - _ => panic!("Field {} location attribute value must be a string literal", field_name) + // Integer literal + syn::MetaItem::NameValue(_, syn::Lit::Int(i, _)) => i as usize, + // String repr of integer literal + syn::MetaItem::NameValue(_, syn::Lit::Str(ref s, _)) => s.parse().unwrap_or_else(|_| { + panic!( + "Field {} location attribute value must contain an integer", + field_name + ) + }), + // Something else + _ => panic!( + "Field {} location attribute value must be a string literal", + field_name + ), }; let field_ty = &field.ty; @@ -71,4 +80,4 @@ fn generate_struct_field_vertex_attrib_pointer_call(field: &syn::Field) -> quote } let offset = offset + ::std::mem::size_of::<#field_ty>(); } -} \ No newline at end of file +}