#[macro_export] #[doc(hidden)]
macro_rules! qecs_newtype {
($(#[$mmm:meta])* pub type $ty:ident: $base:ty) => {
#[derive(Debug, Hash, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
$(#[$mmm])*
pub struct $ty<__B = $base> {
__base: __B
}
qecs_newtype!(IMPL_TRAITS; $ty; $base);
};
($(#[$mmm:meta])* type $ty:ident: $base:ty) => {
#[derive(Debug, Hash, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
$(#[$mmm])*
struct $ty<__B = $base> {
__base: __B
}
qecs_newtype!(IMPL_TRAITS; $ty; $base);
};
(IMPL_TRAITS; $ty:ident; $base:ty) => {
impl<__B> ::std::convert::From<__B> for $ty<__B> {
fn from(core: __B) -> Self { $ty{ __base: core } }
}
impl ::std::convert::Into<$base> for $ty {
fn into(self) -> $base { self.__base }
}
impl<__B> ::std::ops::Deref for $ty<__B> {
type Target = __B;
fn deref(&self) -> &Self::Target { &self.__base }
}
impl<__B> ::std::ops::DerefMut for $ty<__B> {
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.__base }
}
impl<__B, Idx> ::std::ops::Index<Idx> for $ty<__B>
where __B: ::std::ops::Index<Idx>
{
type Output = <__B as ::std::ops::Index<Idx>>::Output;
fn index(&self, index: Idx) -> &Self::Output {
self.__base.index(index)
}
}
impl<__B, Idx> ::std::ops::IndexMut<Idx> for $ty<__B>
where __B: ::std::ops::IndexMut<Idx>
{
fn index_mut(&mut self, index: Idx) -> &mut Self::Output {
self.__base.index_mut(index)
}
}
impl<'a, __B> ::std::iter::IntoIterator for &'a $ty<__B>
where &'a __B: ::std::iter::IntoIterator
{
type Item = <Self::IntoIter as ::std::iter::Iterator>::Item;
type IntoIter = <&'a __B as ::std::iter::IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter { self.__base.into_iter() }
}
impl<'a, __B> ::std::iter::IntoIterator for &'a mut $ty<__B>
where &'a mut __B: ::std::iter::IntoIterator
{
type Item = <Self::IntoIter as ::std::iter::Iterator>::Item;
type IntoIter = <&'a mut __B as ::std::iter::IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter { self.__base.into_iter() }
}
impl<__B> $crate::Component for $ty<__B>
where __B: $crate::Component
{}
impl<__B> $crate::Id for $ty<__B>
where __B: $crate::Id
{}
impl<__B> $crate::IdWithIndex for $ty<__B>
where __B: $crate::IdWithIndex
{
fn max_index() -> usize { __B::max_index() }
fn index(&self) -> usize { self.__base.index() }
}
impl<__B> $crate::Event for $ty<__B>
where __B: $crate::Event
{}
impl<__B> $crate::Action for $ty<__B>
where __B: $crate::Action
{}
impl<__B> $crate::StoreBase for $ty<__B>
where __B: $crate::StoreBase
{
type Id = __B::Id;
fn len(&self) -> usize { self.__base.len() }
fn is_assigned<'id>(&self, id: $crate::Valid<'id, Self::Id>) -> bool {
self.__base.is_assigned(id)
}
fn assign_cloned<'id>(
&mut self,
dest: $crate::Valid<'id, Self::Id>,
src: $crate::Valid<'id, Self::Id>
) -> bool {
self.__base.assign_cloned(dest, src)
}
fn release_drop<'id>(&mut self, id: $crate::Valid<'id, Self::Id>) -> bool {
self.__base.release_drop(id)
}
fn clear(&mut self){ self.__base.clear(); }
}
impl<'a, __B> $crate::_ComponentStore<'a> for $ty<__B>
where
__B: $crate::_ComponentStore<'a>,
{
type _Component = __B::_Component;
type Components = __B::Components;
type ComponentsMut = __B::ComponentsMut;
}
impl<__B> $crate::ComponentStore for $ty<__B>
where
__B: $crate::ComponentStore,
{
type Component = __B::Component;
fn assign<'id, T>(&mut self, id: $crate::Valid<'id, Self::Id>, com: T) -> ::std::option::Option<Self::Component>
where T: Into<Self::Component>
{
self.__base.assign(id, com)
}
fn release<'id>(&mut self, id: $crate::Valid<'id, Self::Id>) -> ::std::option::Option<Self::Component> {
self.__base.release(id)
}
fn get<'id>(&self, id: $crate::Valid<'id, Self::Id>) -> ::std::option::Option<&Self::Component> {
self.__base.get(id)
}
fn get_mut<'id>(&mut self, id: $crate::Valid<'id, Self::Id>) -> ::std::option::Option<&mut Self::Component> {
self.__base.get_mut(id)
}
fn components<'a>(&'a self) -> <Self as $crate::_ComponentStore<'a>>::Components { self.__base.components() }
fn components_mut<'a>(&'a mut self) -> <Self as $crate::_ComponentStore<'a>>::ComponentsMut { self.__base.components_mut() }
}
impl<'a, __B> $crate::_ComponentStoreIter<'a> for $ty<__B>
where
__B: $crate::_ComponentStoreIter<'a>,
{
type Iter = __B::Iter;
type IterMut = __B::IterMut;
}
impl<__B> $crate::ComponentStoreIter for $ty<__B>
where
__B: $crate::ComponentStoreIter,
{
fn iter<'a>(&'a self) -> <Self as $crate::_ComponentStoreIter<'a>>::Iter { self.__base.iter() }
fn iter_mut<'a>(&'a mut self) -> <Self as $crate::_ComponentStoreIter<'a>>::IterMut { self.__base.iter_mut() }
}
impl<__B> $crate::BufferBase for $ty<__B>
where __B: $crate::BufferBase,
{
fn len(&self) -> usize { self.__base.len() }
fn clear(&mut self){ self.__base.clear(); }
}
impl<'a, __B> $crate::_EventBuffer<'a> for $ty<__B>
where __B: $crate::_EventBuffer<'a>,
{
type _Event = __B::_Event;
type Iter = __B::Iter;
}
impl<__B> $crate::EventBuffer for $ty<__B>
where __B: $crate::EventBuffer,
{
type Event = __B::Event;
fn write<T>(&mut self, ev: T)
where T: ::std::convert::Into<Self::Event>
{
self.__base.write(ev)
}
fn iter<'a>(&'a self) -> <Self as $crate::_EventBuffer<'a>>::Iter { self.__base.iter() }
}
};
}