pub struct AlignedBuf<T> { /* private fields */ }Expand description
Growable byte buffer with base pointer aligned to max(align_of::<T>(), 8).
Uses u32 for len/cap (max ~4 GiB, matches Pos(u32)).
The buffer base is always at least 8-byte aligned, which guarantees correct
alignment for all standard primitive types (up to i64/u64). If the root
type T has stricter alignment, the buffer uses that instead.
§Soundness
Allocation: Uses alloc::{alloc, realloc, dealloc} with a layout
whose alignment is BUF_ALIGN. New regions are zero-filled. Allocation
failure calls handle_alloc_error
(never returns null silently).
Provenance exposure: After every grow or clone, the new pointer’s
provenance is exposed via expose_provenance.
This allows Near::get and session operations to
recover the full allocation’s provenance using
with_exposed_provenance when
following self-relative offsets.
Send/Sync: The buffer is exclusively owned (no aliased mutable
pointers). &AlignedBuf only provides &[u8] access. Both impls are
sound.
Implementations§
Source§impl<T> AlignedBuf<T>
impl<T> AlignedBuf<T>
Sourcepub fn with_capacity(capacity: u32) -> Self
pub fn with_capacity(capacity: u32) -> Self
Create an empty buffer pre-allocated to hold at least capacity bytes.
Trait Implementations§
Source§impl<T> Buf for AlignedBuf<T>
Available on crate feature alloc only.
impl<T> Buf for AlignedBuf<T>
alloc only.Source§fn as_mut_ptr(&mut self) -> *mut u8
fn as_mut_ptr(&mut self) -> *mut u8
Source§fn resize(&mut self, new_len: u32, fill: u8)
fn resize(&mut self, new_len: u32, fill: u8)
fill.Source§fn extend_from_slice(&mut self, data: &[u8])
fn extend_from_slice(&mut self, data: &[u8])
Source§fn alloc<U: Flat>(&mut self) -> Pos
fn alloc<U: Flat>(&mut self) -> Pos
U, return its position. Read moreSource§fn expose_provenance(&self)
fn expose_provenance(&self)
Near::get can recover it
via with_exposed_provenance.Source§impl<T> Clone for AlignedBuf<T>
Available on crate feature alloc only.
impl<T> Clone for AlignedBuf<T>
alloc only.Source§impl<T> Default for AlignedBuf<T>
Available on crate feature alloc only.
impl<T> Default for AlignedBuf<T>
alloc only.Source§impl<T> Drop for AlignedBuf<T>
Available on crate feature alloc only.
impl<T> Drop for AlignedBuf<T>
alloc only.impl<T> Send for AlignedBuf<T>
alloc only.impl<T> Sync for AlignedBuf<T>
alloc only.