Skip to content

Commit

Permalink
Merge pull request #532 from kvark/link
Browse files Browse the repository at this point in the history
Implemented Copy and Debug for ShaderParam::Link
  • Loading branch information
kvark committed Feb 5, 2015
2 parents cf19333 + 2efffeb commit 60ee270
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
16 changes: 14 additions & 2 deletions src/gfx_macros/shader_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,27 @@ impl ItemDecorator for ShaderParam {
let link_ty = generic::ty::Literal(
generic::ty::Path::new_local(&link_name[])
);
(*push)(context.item_struct(span, link_ident, link_def));
// process meta parameters
let link_item = context.item_struct(span, link_ident, link_def)
.map(|mut item| {
item.attrs.push(context.attribute(span,
context.meta_list(span, token::InternedString::new("derive"), vec![
context.meta_word(span, token::InternedString::new("Copy")),
context.meta_word(span, token::InternedString::new("Debug")),
])
));
item
});
(*push)(link_item);

// process meta parameters (expecting none)
match meta_item.node {
ast::MetaWord(_) => (), //expected
_ => {
context.span_warn(meta_item.span,
"No arguments are expected for #[shader_param]")
}
}

// #[derive ShaderParam]
let trait_def = generic::TraitDef {
span: span,
Expand Down
22 changes: 17 additions & 5 deletions tests/shader_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,34 @@ extern crate gfx_macros;

mod secret_lib;

use secret_lib::gfx;

// Test all features
#[shader_param]
#[allow(dead_code)]
struct TestParam {
a: i32,
b: [f32; 4],
c: secret_lib::gfx::shade::TextureParam,
d: secret_lib::gfx::RawBufferHandle,
c: gfx::shade::TextureParam,
d: gfx::RawBufferHandle,
e: f32,
#[name = "a_f"]
f: [f32; 4],
}

#[test]
fn test_link_copy() {
// testing if RefBatch is copyable
fn _is_copy<T: Copy>(_t: T) {}
fn _ref_copy(batch: gfx::batch::RefBatch<TestParam>) {
_is_copy(batch)
}
}

#[test]
fn test_shader_param() {
// testing if the types are visible
let _ref: secret_lib::gfx::batch::RefBatch<TestParam>;
let _owned: secret_lib::gfx::batch::OwnedBatch<TestParam>;
// testing if RefBatch can be constructed
let _ref: gfx::batch::RefBatch<TestParam>;
// testing if OwnedBatch can be constructed
let _owned: gfx::batch::OwnedBatch<TestParam>;
}

0 comments on commit 60ee270

Please sign in to comment.