// Tests that generic structs work and are properly bounded extern crate component_group; extern crate specs; extern crate specs_derive; use component_group::ComponentGroup; use specs::{Component, VecStorage, NullStorage}; use specs_derive::Component; trait Foo {} #[derive(Debug, Clone, Component)] #[storage(VecStorage)] pub struct Position {x: i32, y: i32} impl Foo for Position {} #[derive(Debug, Clone, Component)] #[storage(VecStorage)] pub struct Velocity {x: i32, y: i32} // This struct should not have any errors #[derive(ComponentGroup)] struct PlayerComponents where T: Foo + Send + Sync + Component + Clone, U: Send + Sync + Component + Clone { position: Position, foo: T, bar: U, } // impls Component + Clone, but not Foo #[derive(Debug, Default, Clone, Component)] #[storage(NullStorage)] struct NotImplFoo; // impls Component, but not Foo + Clone #[derive(Debug, Default, Component)] #[storage(NullStorage)] struct NotClone; type NotImplFooPlayerComponents = PlayerComponents; fn foo1(c: PlayerComponents) {} // No error fn foo2(c: PlayerComponents) {} // No error fn foo3(c: PlayerComponents) {} //~^ ERROR the trait bound `NotImplFoo: Foo` is not satisfied [E0277] fn foo4(c: PlayerComponents) {} // No error //~^ ERROR the trait bound `NotClone: Clone` is not satisfied [E0277] fn foo5(c: PlayerComponents) {} // No error //~^ ERROR the trait bound `NotClone: Clone` is not satisfied [E0277] //~| ERROR the trait bound `NotClone: Foo` is not satisfied [E0277] fn main() {}