|
1 | 1 | use crate::InOutBuf; |
2 | | -use core::{marker::PhantomData, ptr}; |
3 | | -use hybrid_array::{Array, ArraySize}; |
| 2 | +use core::{marker::PhantomData, 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,32 @@ 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 (buf_in_ptr, buf_out_ptr) = (buf.in_ptr as *const T, buf.out_ptr as *mut T); |
| 164 | + |
| 165 | + Array::from_fn(|i| { |
| 166 | + let split_point = i * N::USIZE; |
| 167 | + |
| 168 | + let (tail_in_ptr, tail_out_ptr) = |
| 169 | + unsafe { (buf_in_ptr.add(split_point), buf_out_ptr.add(split_point)) }; |
| 170 | + |
| 171 | + InOut { |
| 172 | + in_ptr: tail_in_ptr as *const Array<T, N>, |
| 173 | + out_ptr: tail_out_ptr as *mut Array<T, N>, |
| 174 | + _pd: PhantomData, |
| 175 | + } |
| 176 | + }) |
| 177 | + } |
| 178 | +} |
| 179 | + |
154 | 180 | impl<N: ArraySize> InOut<'_, '_, Array<u8, N>> { |
155 | 181 | /// XOR `data` with values behind the input slice and write |
156 | 182 | /// result to the output slice. |
|
0 commit comments