1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use std::mem;

// +CL
pub trait CL{fn c_len(&self)->usize;}
macro_rules! cl_impls_2{($type:ty,$($N:expr)+)=>{$(
    impl CL for [$type;$N]{fn c_len(&self)->usize{$N}}
)+}}
macro_rules! cl_impls{($($type:ty)+)=>{$(
    impl CL for $type{fn c_len(&self)->usize{1}}
    impl CL for Vec<$type>{fn c_len(&self)->usize{self.len()}}
    cl_impls_2!($type,
        00 01 02 03 04 05 06 07 08 09
        10 11 12 13 14 15 16 17 18 19
        20 21 22 23 24 25 26 27 28 29
        30 31 32 33 34 35 36 37 38 39
    );
)+}}
cl_impls!(u8 i8 u16 i16 u32 i32 u64 i64);
impl CL for String{fn c_len(&self)->usize{self.len()}}
impl CL for str{fn c_len(&self)->usize{self.len()}}
impl<'a,T> CL for &'a T where T:CL+?Sized{fn c_len(&self)->usize{(*self).c_len()}}
// -CL


// +CS
pub trait CS{fn c_size(&self)->usize;}
macro_rules! cs_impls_2{($type:ty,$($N:expr)+)=>{$(
    impl CS for [$type;$N]{fn c_size(&self)->usize{mem::size_of::<$type>()}}
)+}}
macro_rules! cs_impls{($($type:ty)+)=>{$(
    impl CS for $type{fn c_size(&self)->usize{mem::size_of::<$type>()}}
    impl CS for Vec<$type>{fn c_size(&self)->usize{mem::size_of::<$type>()}}
    cs_impls_2!($type,
        00 01 02 03 04 05 06 07 08 09
        10 11 12 13 14 15 16 17 18 19
        20 21 22 23 24 25 26 27 28 29
        30 31 32 33 34 35 36 37 38 39
    );
)+}}
cs_impls!(u8 i8 u16 i16 u32 i32 u64 i64);
impl CS for String{fn c_size(&self)->usize{1}}
impl CS for str{fn c_size(&self)->usize{1}}
impl<'a,T> CS for &'a T where T:CS+?Sized{fn c_size(&self)->usize{(*self).c_size()}}
// -CS


// +CCPP
pub trait CCPP<U>{fn cp_ptr(&self)->*const U;}
macro_rules! ccpp_impls_2{($t1:ty,$t2:ty,$($N:expr)+)=>{$(
    impl CCPP<$t2> for [$t1;$N]{fn cp_ptr(&self)->*const $t2{self[..].as_ptr() as *const $t2}}
)+}}
macro_rules! ccpp_impls{
    ($([$t1:ty,$t2:ty]),*)=>{
        $(
            impl CCPP<$t2> for $t1{fn cp_ptr(&self)->*const $t2{(self as *const $t1) as *const $t2}}
            impl CCPP<$t2> for Vec<$t1>{fn cp_ptr(&self)->*const $t2{self.as_ptr() as *const $t2}}
            ccpp_impls_2!($t1,$t2,
                00 01 02 03 04 05 06 07 08 09
                10 11 12 13 14 15 16 17 18 19
                20 21 22 23 24 25 26 27 28 29
                30 31 32 33 34 35 36 37 38 39
            );
        )+
    }
}
ccpp_impls!([u8,u8],[i8,u8],[u16,u16],[i16,u16],[u32,u32],[i32,u32],[u64,u64],[i64,u64]);
impl CCPP<u8> for String{fn cp_ptr(&self)->*const u8{self.as_ptr()}}
impl CCPP<u8> for str{fn cp_ptr(&self)->*const u8{self.as_ptr()}}
impl<'a,T,U> CCPP<U> for &'a T where T:CCPP<U>{fn cp_ptr(&self)->*const U{(*self).cp_ptr()}}
// -CCPP

// +C8CPP
pub trait C8CPP{fn c8p_ptr(&self)->*const u8;}
macro_rules! c8cpp_impls_2{($t:ty,$($N:expr)+)=>{$(
    impl C8CPP for [$t;$N]{fn c8p_ptr(&self)->*const u8{self[..].as_ptr() as *const u8}}
)+}}
macro_rules! c8cpp_impls{
    ($($t:ty),*)=>{
        $(
            impl C8CPP for $t{fn c8p_ptr(&self)->*const u8{(self as *const $t) as *const u8}}
            impl C8CPP for Vec<$t>{fn c8p_ptr(&self)->*const u8{self.as_ptr() as *const u8}}
            c8cpp_impls_2!($t,
                00 01 02 03 04 05 06 07 08 09
                10 11 12 13 14 15 16 17 18 19
                20 21 22 23 24 25 26 27 28 29
                30 31 32 33 34 35 36 37 38 39
            );
        )+
    }
}
c8cpp_impls!(u8,i8);
impl C8CPP for String{fn c8p_ptr(&self)->*const u8{self.as_ptr()}}
impl C8CPP for str{fn c8p_ptr(&self)->*const u8{self.as_ptr()}}
impl<'a,T> C8CPP for &'a T where T:C8CPP{fn c8p_ptr(&self)->*const u8{(*self).c8p_ptr()}}
// -C8CPP

// +C16CPP
pub trait C16CPP{fn c16p_ptr(&self)->*const u16;}
macro_rules! c16cpp_impls_2{($t:ty,$($N:expr)+)=>{$(
    impl C16CPP for [$t;$N]{fn c16p_ptr(&self)->*const u16{self[..].as_ptr() as *const u16}}
)+}}
macro_rules! c16cpp_impls{
    ($($t:ty),*)=>{
        $(
            impl C16CPP for $t{fn c16p_ptr(&self)->*const u16{(self as *const $t) as *const u16}}
            impl C16CPP for Vec<$t>{fn c16p_ptr(&self)->*const u16{self.as_ptr() as *const u16}}
            c16cpp_impls_2!($t,
                00 01 02 03 04 05 06 07 08 09
                10 11 12 13 14 15 16 17 18 19
                20 21 22 23 24 25 26 27 28 29
                30 31 32 33 34 35 36 37 38 39
            );
        )+
    }
}
c16cpp_impls!(u16,i16);
impl<'a,T> C16CPP for &'a T where T:C16CPP{fn c16p_ptr(&self)->*const u16{(*self).c16p_ptr()}}
// -C16CPP

// +C32CPP
pub trait C32CPP{fn c32p_ptr(&self)->*const u32;}
macro_rules! c32cpp_impls_2{($t:ty,$($N:expr)+)=>{$(
    impl C32CPP for [$t;$N]{fn c32p_ptr(&self)->*const u32{self[..].as_ptr() as *const u32}}
)+}}
macro_rules! c32cpp_impls{
    ($($t:ty),*)=>{
        $(
            impl C32CPP for $t{fn c32p_ptr(&self)->*const u32{(self as *const $t) as *const u32}}
            impl C32CPP for Vec<$t>{fn c32p_ptr(&self)->*const u32{self.as_ptr() as *const u32}}
            c32cpp_impls_2!($t,
                00 01 02 03 04 05 06 07 08 09
                10 11 12 13 14 15 16 17 18 19
                20 21 22 23 24 25 26 27 28 29
                30 31 32 33 34 35 36 37 38 39
            );
        )+
    }
}
c32cpp_impls!(u16,i16);
impl<'a,T> C32CPP for &'a T where T:C32CPP{fn c32p_ptr(&self)->*const u32{(*self).c32p_ptr()}}
// -C32CPP

pub mod empty{
    pub enum ENUM0{}
    pub enum ENUM1{}
    pub enum ENUM2{}
    pub enum ENUM3{}
    pub enum ENUM4{}
    pub enum ENUM5{}
    pub enum ENUM6{}
    pub enum ENUM7{}
}