(&mut self)
| 16 | |
| 17 | impl<T: Encode, const N: usize> Encoder<[T; N]> for ArrayEncoder<T, N> { |
| 18 | fn as_primitive(&mut self) -> Option<&mut FastVec<[T; N]>> { |
| 19 | // FastVec doesn't work on ZST. |
| 20 | if N == 0 { |
| 21 | return None; |
| 22 | } |
| 23 | self.0.as_primitive().map(|v| { |
| 24 | debug_assert!(v.len() % N == 0); |
| 25 | // Safety: FastVec uses pointers for len/cap unlike Vec, so casting to FastVec<[T; N]> |
| 26 | // is safe as long as `v.len() % N == 0`. This will always be the case since we only |
| 27 | // encode in chunks of N. |
| 28 | // NOTE: If panics occurs during ArrayEncoder::encode and Buffer is reused, this |
| 29 | // invariant can be violated. Luckily primitive encoders never panic. |
| 30 | // TODO std::mem::take Buffer while encoding to avoid corrupted buffers. |
| 31 | unsafe { std::mem::transmute(v) } |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | #[inline(always)] |
| 36 | fn encode(&mut self, array: &[T; N]) { |
no outgoing calls
no test coverage detected