|
1 | 1 | use crate::InOutBuf;
|
2 |
| -use core::{marker::PhantomData, ptr}; |
3 |
| -use hybrid_array::{Array, ArraySize}; |
| 2 | +use core::{marker::PhantomData, mem::MaybeUninit, ops::Mul, ptr}; |
| 3 | +use hybrid_array::{Array, ArraySize, typenum::Prod}; |
4 | 4 |
|
5 | 5 | /// Custom pointer type which contains one immutable (input) and one mutable
|
6 | 6 | /// (output) pointer, which are either equal or non-overlapping.
|
@@ -151,6 +151,35 @@ impl<'inp, 'out, T, N: ArraySize> InOut<'inp, 'out, Array<T, N>> {
|
151 | 151 | }
|
152 | 152 | }
|
153 | 153 |
|
| 154 | +impl<'inp, 'out, T, N, M> From<InOut<'inp, 'out, Array<T, Prod<N, M>>>> |
| 155 | + for Array<InOut<'inp, 'out, Array<T, N>>, M> |
| 156 | +where |
| 157 | + N: ArraySize, |
| 158 | + M: ArraySize, |
| 159 | + N: Mul<M>, |
| 160 | + Prod<N, M>: ArraySize, |
| 161 | +{ |
| 162 | + fn from(buf: InOut<'inp, 'out, Array<T, Prod<N, M>>>) -> Self { |
| 163 | + let split_point = N::USIZE; |
| 164 | + let mut out = Array::<MaybeUninit<InOut<Array<T, N>>>, M>::uninit(); |
| 165 | + let (mut tail_in_ptr, mut tail_out_ptr) = (buf.in_ptr as *const T, buf.out_ptr as *mut T); |
| 166 | + |
| 167 | + for i in 0..M::USIZE { |
| 168 | + let el = InOut { |
| 169 | + in_ptr: tail_in_ptr as *const Array<T, N>, |
| 170 | + out_ptr: tail_out_ptr as *mut Array<T, N>, |
| 171 | + _pd: PhantomData, |
| 172 | + }; |
| 173 | + out[i].write(el); |
| 174 | + |
| 175 | + (tail_in_ptr, tail_out_ptr) = |
| 176 | + unsafe { (tail_in_ptr.add(split_point), tail_out_ptr.add(split_point)) }; |
| 177 | + } |
| 178 | + |
| 179 | + unsafe { out.assume_init() } |
| 180 | + } |
| 181 | +} |
| 182 | + |
154 | 183 | impl<N: ArraySize> InOut<'_, '_, Array<u8, N>> {
|
155 | 184 | /// XOR `data` with values behind the input slice and write
|
156 | 185 | /// result to the output slice.
|
|
0 commit comments