unsafe fn mmap_field_vec_unchecked<F: PrimeField>(
bytes: &[u8],
count: usize,
) -> Vec<F>Expand description
Zero-copy: constructs a Vec<F> whose backing storage is the mmap
region itself, via Vec::from_raw_parts(mmap_ptr, len, len).
This is infallible by design: it performs no validation and simply
reinterprets the bytes. All length/alignment validation must be done up
front (see validate_field_section) so that this constructor — and
therefore the first live mmap-backed Vec — is only ever reached once the
entire file is known to be well-formed. That ordering is what makes the
reader panic-free: an Err returned after one of these Vecs existed
would drop it, calling the global allocator on mmap memory (undefined
behaviour, observed as a free(): invalid pointer abort).
§Safety
bytes.len()must equalcount * FIELD_ELEMENT_BYTES(caller guarantees this viavalidate_field_section).- The returned
Vec<F>must never be dropped normally and must never grow: both would calldealloc/reallocon the mmap pointer. Callers keep it inside acore::mem::ManuallyDropcontainer (seeMmapProverIndex) soVec::dropnever runs. bytesmust be aligned forF(8-byte alignment suffices forBigInt<4>; the format’s 32-byte section alignment covers this) and the underlying mmap must outlive the returnedVec<F>.