Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros 1.1 custom derives #1183

Merged
merged 4 commits into from Mar 7, 2017

Conversation

@kvark
Copy link
Member

commented Feb 10, 2017

This PR introduces custom derive macros VertexData and ConstantBuffer. It is an alternative to macro-generated gfx_vertex_struct and gfx_constant_struct, aimed at better flexibility.

Current limitations:

  • the shader name has to match the field name
  • gfx namespace has to be visible

New features:

  • you control the privacy of the struct and its fields
  • you can derive more traits (like Eq) at will
  • less magic is going on with your code

Published crate: https://crates.io/crates/gfx_macros/0.2.0

Example:

#[derive(VertexData)]
struct Vertex {
    a_pos: [u8; 4],
    a_tex_coord: [f32; 2],
}

@kvark kvark force-pushed the kvark:macros branch from 8aecaf1 to 276f054 Feb 10, 2017

homu added a commit that referenced this pull request Feb 10, 2017

Auto merge of #1184 - gfx-rs:kvark-win, r=kvark
AppVeyor Rust version bump to 1.15

Required for #1183

@kvark kvark force-pushed the kvark:macros branch from 276f054 to 01c96c4 Mar 7, 2017

@kvark

This comment has been minimized.

Copy link
Member Author

commented Mar 7, 2017

r? anyone

use proc_macro::TokenStream;


#[proc_macro_derive(GfxVertexFormat)]

This comment has been minimized.

Copy link
@Bastacyclop

Bastacyclop Mar 7, 2017

Member

is the Gfx prefix necessary ? (I hope there is a way to rename a macro on the user side if he has clashes)

let name = &ast.ident;
let fields = match ast.body {
syn::Body::Struct(syn::VariantData::Struct(ref fields)) => fields,
_ => panic!("`GfxStruct` can only be derived for structs"),

This comment has been minimized.

Copy link
@Bastacyclop

Bastacyclop Mar 7, 2017

Member

We are not really deriving GfxStruct, I think rustc already wraps the derive panics inside a pretty message with the derive name and location.

This comment has been minimized.

Copy link
@kvark

kvark Mar 8, 2017

Author Member

Nicely spotted! Fixed in #1207

@kvark kvark force-pushed the kvark:macros branch from 7c4a503 to 71019a8 Mar 7, 2017

@kvark

This comment has been minimized.

Copy link
Member Author

commented Mar 7, 2017

Thanks @Bastacyclop ! Fixed now, merging in an hour.

@kvark kvark merged commit f751dfd into gfx-rs:master Mar 7, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@kvark kvark deleted the kvark:macros branch Mar 7, 2017

@kvark kvark changed the title [WIP] Macros 1.1 Macros 1.1 custom derives Mar 7, 2017

@ebkalderon

This comment has been minimized.

Copy link
Contributor

commented Mar 11, 2017

This is fantastic! ❤️ I think this also means that my previous issues with #![deny(missing_docs)] is no longer a problem, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.