|
| 1 | +#[repr(C, u8)] |
| 2 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 3 | +enum CustomDiscriminantsDiscriminant { |
| 4 | + A = 10, |
| 5 | + B = 20, |
| 6 | + C, |
| 7 | + D = some_function(), |
| 8 | +} |
| 9 | +#[allow(dead_code)] |
| 10 | +#[derive(Copy, Clone)] |
| 11 | +union CustomDiscriminantsField0 { |
| 12 | + a: (), |
| 13 | + b: String, |
| 14 | + c: (), |
| 15 | + d: (), |
| 16 | +} |
| 17 | +#[allow(dead_code)] |
| 18 | +#[derive(Copy, Clone)] |
| 19 | +union CustomDiscriminantsField1 { |
| 20 | + a: (), |
| 21 | + b: u32, |
| 22 | + c: (), |
| 23 | + d: (), |
| 24 | +} |
| 25 | +#[allow(dead_code)] |
| 26 | +struct CustomDiscriminantsRef<'soa> { |
| 27 | + discriminant: &'soa CustomDiscriminantsDiscriminant, |
| 28 | + _0: &'soa CustomDiscriminantsField0, |
| 29 | + _1: &'soa CustomDiscriminantsField1, |
| 30 | +} |
| 31 | +impl<'soa> Copy for CustomDiscriminantsRef<'soa> {} |
| 32 | +impl<'soa> Clone for CustomDiscriminantsRef<'soa> { |
| 33 | + fn clone(&self) -> Self { |
| 34 | + *self |
| 35 | + } |
| 36 | +} |
| 37 | +#[allow(dead_code)] |
| 38 | +struct CustomDiscriminantsMut<'soa> { |
| 39 | + discriminant: &'soa CustomDiscriminantsDiscriminant, |
| 40 | + _0: &'soa mut CustomDiscriminantsField0, |
| 41 | + _1: &'soa mut CustomDiscriminantsField1, |
| 42 | +} |
| 43 | +#[allow(dead_code)] |
| 44 | +struct CustomDiscriminantsSlice<'soa> { |
| 45 | + discriminant: &'soa [CustomDiscriminantsDiscriminant], |
| 46 | + _0: &'soa [CustomDiscriminantsField0], |
| 47 | + _1: &'soa [CustomDiscriminantsField1], |
| 48 | +} |
| 49 | +impl<'soa> Copy for CustomDiscriminantsSlice<'soa> {} |
| 50 | +impl<'soa> Clone for CustomDiscriminantsSlice<'soa> { |
| 51 | + fn clone(&self) -> Self { |
| 52 | + *self |
| 53 | + } |
| 54 | +} |
| 55 | +#[allow(dead_code)] |
| 56 | +struct CustomDiscriminantsSliceMut<'soa> { |
| 57 | + discriminant: &'soa mut [CustomDiscriminantsDiscriminant], |
| 58 | + _0: &'soa mut [CustomDiscriminantsField0], |
| 59 | + _1: &'soa mut [CustomDiscriminantsField1], |
| 60 | +} |
| 61 | +unsafe impl soavec::SoAble for CustomDiscriminants { |
| 62 | + type TupleRepr = ( |
| 63 | + CustomDiscriminantsDiscriminant, |
| 64 | + CustomDiscriminantsField0, |
| 65 | + CustomDiscriminantsField1, |
| 66 | + ); |
| 67 | + type Ref<'soa> |
| 68 | + = CustomDiscriminantsRef<'soa> |
| 69 | + where |
| 70 | + Self: 'soa; |
| 71 | + type Mut<'soa> |
| 72 | + = CustomDiscriminantsMut<'soa> |
| 73 | + where |
| 74 | + Self: 'soa; |
| 75 | + type Slice<'soa> |
| 76 | + = CustomDiscriminantsSlice<'soa> |
| 77 | + where |
| 78 | + Self: 'soa; |
| 79 | + type SliceMut<'soa> |
| 80 | + = CustomDiscriminantsSliceMut<'soa> |
| 81 | + where |
| 82 | + Self: 'soa; |
| 83 | + fn into_tuple(value: Self) -> Self::TupleRepr { |
| 84 | + match value { |
| 85 | + Self::A => ( |
| 86 | + CustomDiscriminantsDiscriminant::A, |
| 87 | + CustomDiscriminantsField0 { a: () }, |
| 88 | + CustomDiscriminantsField1 { a: () }, |
| 89 | + ), |
| 90 | + Self::B(__field0, __field1) => ( |
| 91 | + CustomDiscriminantsDiscriminant::B, |
| 92 | + CustomDiscriminantsField0 { b: __field0 }, |
| 93 | + CustomDiscriminantsField1 { b: __field1 }, |
| 94 | + ), |
| 95 | + Self::C => ( |
| 96 | + CustomDiscriminantsDiscriminant::C, |
| 97 | + CustomDiscriminantsField0 { c: () }, |
| 98 | + CustomDiscriminantsField1 { c: () }, |
| 99 | + ), |
| 100 | + Self::D => ( |
| 101 | + CustomDiscriminantsDiscriminant::D, |
| 102 | + CustomDiscriminantsField0 { d: () }, |
| 103 | + CustomDiscriminantsField1 { d: () }, |
| 104 | + ), |
| 105 | + } |
| 106 | + } |
| 107 | + fn from_tuple(value: Self::TupleRepr) -> Self { |
| 108 | + let (__disc, __union0, __union1) = value; |
| 109 | + match __disc { |
| 110 | + CustomDiscriminantsDiscriminant::A => Self::A, |
| 111 | + CustomDiscriminantsDiscriminant::B => { |
| 112 | + let __field0 = unsafe { __union0.b }; |
| 113 | + let __field1 = unsafe { __union1.b }; |
| 114 | + Self::B(__field0, __field1) |
| 115 | + } |
| 116 | + CustomDiscriminantsDiscriminant::C => Self::C, |
| 117 | + CustomDiscriminantsDiscriminant::D => Self::D, |
| 118 | + } |
| 119 | + } |
| 120 | + fn as_ref<'soa>( |
| 121 | + _: std::marker::PhantomData<&'soa Self>, |
| 122 | + value: <Self::TupleRepr as soavec::SoATuple>::Pointers, |
| 123 | + ) -> Self::Ref<'soa> { |
| 124 | + let (__disc_ptr, __union0, __union1) = value; |
| 125 | + unsafe { |
| 126 | + CustomDiscriminantsRef { |
| 127 | + discriminant: &*(__disc_ptr.as_ptr() as *const _), |
| 128 | + _0: __union0.as_ref(), |
| 129 | + _1: __union1.as_ref(), |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + fn as_mut<'soa>( |
| 134 | + _: std::marker::PhantomData<&'soa mut Self>, |
| 135 | + value: <Self::TupleRepr as soavec::SoATuple>::Pointers, |
| 136 | + ) -> Self::Mut<'soa> { |
| 137 | + let (__disc_ptr, mut __union0, mut __union1) = value; |
| 138 | + unsafe { |
| 139 | + CustomDiscriminantsMut { |
| 140 | + discriminant: &*(__disc_ptr.as_ptr() as *const _), |
| 141 | + _0: __union0.as_mut(), |
| 142 | + _1: __union1.as_mut(), |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + fn as_slice<'soa>( |
| 147 | + _: std::marker::PhantomData<&'soa Self>, |
| 148 | + value: <Self::TupleRepr as soavec::SoATuple>::Pointers, |
| 149 | + len: u32, |
| 150 | + ) -> Self::Slice<'soa> { |
| 151 | + let __soa_len = len as usize; |
| 152 | + let (__disc_ptr, __union0, __union1) = value; |
| 153 | + unsafe { |
| 154 | + CustomDiscriminantsSlice { |
| 155 | + discriminant: core::slice::from_raw_parts( |
| 156 | + __disc_ptr.as_ptr() as *const _, |
| 157 | + __soa_len, |
| 158 | + ), |
| 159 | + _0: core::slice::from_raw_parts(__union0.as_ptr(), __soa_len), |
| 160 | + _1: core::slice::from_raw_parts(__union1.as_ptr(), __soa_len), |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + fn as_mut_slice<'soa>( |
| 165 | + _: std::marker::PhantomData<&'soa mut Self>, |
| 166 | + value: <Self::TupleRepr as soavec::SoATuple>::Pointers, |
| 167 | + len: u32, |
| 168 | + ) -> Self::SliceMut<'soa> { |
| 169 | + let __soa_len = len as usize; |
| 170 | + let (__disc_ptr, __union0, __union1) = value; |
| 171 | + unsafe { |
| 172 | + CustomDiscriminantsSliceMut { |
| 173 | + discriminant: core::slice::from_raw_parts_mut( |
| 174 | + __disc_ptr.as_ptr() as *mut _, |
| 175 | + __soa_len, |
| 176 | + ), |
| 177 | + _0: core::slice::from_raw_parts_mut(__union0.as_ptr(), __soa_len), |
| 178 | + _1: core::slice::from_raw_parts_mut(__union1.as_ptr(), __soa_len), |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | +} |
0 commit comments