MCPcopy Create free account
hub / github.com/SoftbearStudios/bitcode / as_primitive

Method as_primitive

src/derive/array.rs:18–33  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

16
17impl<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]) {

Callers 7

encodeMethod · 0.45
encode_vectoredMethod · 0.45
encodeMethod · 0.45
encode_vectoredMethod · 0.45
decode_in_placeMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected