qecs-core 0.0.17

Soon to be highly flexible Entity-Component-System framework, core lib.

#[macro_export] 
macro_rules! qecs_newtype {

    // pub single
    ($(#[$mmm:meta])* pub type $ty:ident: $base:ty) => {
        qecs_newtype!($(#[$mmm])* pub type $ty: $base;);
    };

    // non-pub single
    ($(#[$mmm:meta])* type $ty:ident: $base:ty) => {
        qecs_newtype!($(#[$mmm])* type $ty: $base;);
    };

    // pub
    ($($(#[$mmm:meta])* pub type $ty:ident: $base:ty;)+) => {$(

        $(#[$mmm])*
        pub struct $ty<__B = $base> {
            __base: __B
        }

        qecs_newtype!(@impl_traits; $ty; $base);

    )+};

    // non-pub
    ($($(#[$mmm:meta])* type $ty:ident: $base:ty;)+) => {$(

        $(#[$mmm])*
        struct $ty {
            __base: $base
        }

        qecs_newtype!(@impl_traits; $ty; $base);

    )+};

    // (non-'derive'-able) trait implementations
    (@impl_traits; $ty:ident; $base:ty) => {

        impl ::std::convert::From<$base> for $ty {
            fn from(base: $base) -> Self { $ty{ __base: base } }
        }

        impl ::std::convert::Into<$base> for $ty {
            fn into(self) -> $base { self.__base }
        }

        impl ::std::ops::Deref for $ty {
            type Target = $base;
            fn deref(&self) -> &Self::Target { &self.__base }
        }

        impl ::std::ops::DerefMut for $ty {
            fn deref_mut(&mut self) -> &mut Self::Target { &mut self.__base }
        }

    };
}