diff options
Diffstat (limited to 'src/bundle.rs')
| -rw-r--r-- | src/bundle.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/bundle.rs b/src/bundle.rs new file mode 100644 index 0000000..08753a7 --- /dev/null +++ b/src/bundle.rs @@ -0,0 +1,34 @@ +use super::Entity; +use super::component::{Component, ComponentStorage}; + +pub trait ComponentBundle<W> { + fn insert(self, world: &mut W, entity: Entity); +} + +macro_rules! impl_bundle_tuple { + ($($T:ident),+) => { + impl<W, $($T),+> ComponentBundle<W> for ($($T,)+) + where + $( + $T: Component, + W: ComponentStorage<$T>, + )+ + { + #[allow(non_snake_case)] + fn insert(self, world: &mut W, entity: Entity) { + let ($($T,)+) = self; + + $( + world.insert(entity, $T); + )+ + } + } + }; +} + +impl_bundle_tuple!(A); +impl_bundle_tuple!(A, B); +impl_bundle_tuple!(A, B, C); +impl_bundle_tuple!(A, B, C, D); +impl_bundle_tuple!(A, B, C, D, E); +impl_bundle_tuple!(A, B, C, D, E, F); |
