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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use crate::{
    alignment::{Aligned, Unaligned},
    ext::{ROExtAcc, ROExtOps, ROExtRawAcc, ROExtRawMutAcc, ROExtRawMutOps, ROExtRawOps},
    FieldOffset,
};

//////////////////////////////////////////////////////////////////////////////

unsafe impl<S> ROExtAcc for S {
    #[inline(always)]
    fn f_get<F>(&self, offset: FieldOffset<Self, F, Aligned>) -> &F {
        unsafe { impl_fo!(fn get<S, F, Aligned>(offset, self)) }
    }
    #[inline(always)]
    fn f_get_mut<F>(&mut self, offset: FieldOffset<Self, F, Aligned>) -> &mut F {
        unsafe { impl_fo!(fn get_mut<S, F, Aligned>(offset, self)) }
    }

    #[inline(always)]
    fn f_get_ptr<F, A>(&self, offset: FieldOffset<Self, F, A>) -> *const F {
        unsafe { impl_fo!(fn get_ptr<S, F, A>(offset, self)) }
    }

    #[inline(always)]
    fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<Self, F, A>) -> *mut F {
        unsafe { impl_fo!(fn get_mut_ptr<S, F, A>(offset, self)) }
    }
}

macro_rules! impl_ROExtOps {
    ($A:ident) => {

        unsafe impl<S> ROExtOps<$A> for S {
            #[inline(always)]
            fn f_replace<F>(&mut self, offset: FieldOffset<Self, F, $A>, value: F) -> F{
                unsafe{ impl_fo!(fn replace_mut<S, F, $A>(offset, self, value)) }
            }

            #[inline(always)]
            fn f_swap<F>(&mut self, offset: FieldOffset<Self, F, $A>, right: &mut S){
                unsafe{ impl_fo!(fn swap_mut<S, F, $A>(offset, self, right)) }

            }

            #[inline(always)]
            fn f_get_copy<F>(&self, offset: FieldOffset<Self, F, $A>) -> F
            where
                F: Copy
            {
                unsafe{ impl_fo!(fn get_copy<S, F, $A>(offset, self)) }
            }
        }
    };
}

impl_ROExtOps! {Aligned}
impl_ROExtOps! {Unaligned}

//////////////////////////////////////////////////////////////////////////////

macro_rules! impl_ROExtRaw {
    ($($ptr:tt)*)=>{
        impl_ROExtRawOps! {Aligned, [$($ptr)*]}
        impl_ROExtRawOps! {Unaligned, [$($ptr)*]}

        unsafe impl<S> ROExtRawAcc for $($ptr)* S {
            #[inline(always)]
            unsafe fn f_raw_get<F, A>(self, offset: FieldOffset<Self::Target, F, A>) -> *const F {
                impl_fo!(fn raw_get<Self::Target, F, A>(offset, self))
            }
        }
    }
}

macro_rules! impl_ROExtRawMut {
    ($($ptr:tt)*)=>{
        impl_ROExtRawMutOps! {Aligned, [$($ptr)*]}
        impl_ROExtRawMutOps! {Unaligned, [$($ptr)*]}

        unsafe impl<S> ROExtRawMutAcc for $($ptr)* S {
            #[inline(always)]
            unsafe fn f_raw_get_mut<F, A>(self, offset: FieldOffset<Self::Target, F, A>) -> *mut F {
                impl_fo!(fn raw_get_mut<Self::Target, F, A>(offset, self))
            }
        }
    }
}

macro_rules! impl_ROExtRawOps {
    ($A:ident, [$($ptr:tt)*])=>{
        unsafe impl<S> ROExtRawOps<$A> for $($ptr)* S {
            #[inline(always)]
            unsafe fn f_read_copy<F>(self, offset: FieldOffset<Self::Target, F, $A>) -> F
            where
                F: Copy
            {
                impl_fo!(fn read_copy<Self::Target, F, $A>(offset, self))
            }

            #[inline(always)]
            unsafe fn f_read<F>(self, offset: FieldOffset<Self::Target, F, $A>) -> F {
                impl_fo!(fn read<Self::Target, F, $A>(offset, self))
            }
        }
    };
}

macro_rules! impl_ROExtRawMutOps {
    ($A:ident, [$($ptr:tt)*])=>{
        unsafe impl<S> ROExtRawMutOps<$A> for $($ptr)* S {
            #[inline(always)]
            unsafe fn f_write<F>(self, offset: FieldOffset<Self::Target, F, $A>, value: F) {
                impl_fo!(fn write<Self::Target, F, $A>(offset, self, value))
            }

            #[inline(always)]
            unsafe fn f_copy_from<F>(
                self,
                offset: FieldOffset<Self::Target, F, $A>,
                source: *const Self::Target,
            ) {
                impl_fo!(fn copy<Self::Target, F, $A>(offset, source, self))
            }

            #[inline(always)]
            unsafe fn f_copy_from_nonoverlapping<F>(
                self,
                offset: FieldOffset<Self::Target, F, $A>,
                source: *const Self::Target,
            ) {
                impl_fo!(fn copy_nonoverlapping<Self::Target, F, $A>(offset, source, self))
            }

            #[inline(always)]
            unsafe fn f_replace_raw<F>(
                self,
                offset: FieldOffset<Self::Target, F, $A>,
                value: F,
            ) -> F {
                impl_fo!(fn replace<Self::Target, F, $A>(offset, self, value))
            }

            #[inline(always)]
            unsafe fn f_swap_raw<F>(
                self,
                offset: FieldOffset<Self::Target, F, $A>,
                right: *mut Self::Target,
            ) {
                impl_fo!(fn swap<Self::Target, F, $A>(offset, self, right))
            }

            #[inline(always)]
            unsafe fn f_swap_nonoverlapping<F>(
                self,
                offset: FieldOffset<Self::Target, F, $A>,
                right: *mut Self::Target
            ) {
                impl_fo!(fn swap_nonoverlapping<Self::Target, F, $A>(offset, self, right))
            }
        }
    }
}

impl_ROExtRaw! {*const}
impl_ROExtRaw! {*mut}

impl_ROExtRawMut! {*mut}