Skip to content

Commit

Permalink
Modify Derive to allow unit structs for RenderResources. (bevyengine#…
Browse files Browse the repository at this point in the history
  • Loading branch information
OptimisticPeach authored Dec 23, 2020
1 parent acc29ec commit cbc0fe1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion crates/bevy_derive/src/render_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/mesh_custom_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cbc0fe1

Please sign in to comment.