Modify Derive to allow unit structs for RenderResources. (#1089)

This commit is contained in:
Patrik Buhring 2020-12-23 18:21:10 -05:00 committed by GitHub
parent acc29ec719
commit cbc0fe1416
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -2,7 +2,8 @@ use crate::modules::{get_modules, get_path};
use proc_macro::TokenStream;
use quote::{format_ident, quote};
use syn::{
parse::ParseStream, parse_macro_input, Data, DataStruct, DeriveInput, Field, Fields, Path,
parse::ParseStream, parse_macro_input, punctuated::Punctuated, Data, DataStruct, DeriveInput,
Field, Fields, Path,
};
#[derive(Default)]
@ -72,11 +73,17 @@ pub fn derive_render_resources(input: TokenStream) -> TokenStream {
}
})
} else {
let empty = Punctuated::new();
let fields = match &ast.data {
Data::Struct(DataStruct {
fields: Fields::Named(fields),
..
}) => &fields.named,
Data::Struct(DataStruct {
fields: Fields::Unit,
..
}) => &empty,
_ => panic!("Expected a struct with named fields."),
};
let field_attributes = fields

View file

@ -21,7 +21,7 @@ fn main() {
#[derive(RenderResources, Default, TypeUuid)]
#[uuid = "0320b9b8-b3a3-4baa-8bfa-c94008177b17"]
struct MyMaterialWithVertexColorSupport {}
struct MyMaterialWithVertexColorSupport;
const VERTEX_SHADER: &str = r#"
#version 450