pub struct Section<'view> { /* private fields */ }Expand description
Borrowed view of one validated section in a snapshot.
A Section carries the section’s byte payload along with its declared
metadata. Payload bytes are bounds- and overlap-checked at snapshot open
time. Typed-slice access via Section::try_as_slice verifies the
actual borrowed pointer’s alignment at the call site.
§Performance
All methods are O(1) or O(payload.len()) for typed conversions.
Implementations§
Source§impl<'view> Section<'view>
impl<'view> Section<'view>
Sourcepub const fn declared_alignment(&self) -> usize
pub const fn declared_alignment(&self) -> usize
Returns the alignment the producer declared for this payload.
This is metadata recorded at build time, not a guarantee about the
actual borrowed pointer. Callers that intend to interpret the payload
as a typed slice should prefer Section::try_as_slice, which
checks the actual payload pointer.
§Performance
This method is O(1).
Sourcepub fn try_as_slice<T>(&self) -> Result<&'view [T], SectionViewError>
pub fn try_as_slice<T>(&self) -> Result<&'view [T], SectionViewError>
Borrows the payload as a typed slice of T.
Errors if (a) payload.len() is not a multiple of
core::mem::size_of::<T>() or (b) the payload’s actual base address
does not satisfy core::mem::align_of::<T>(). The producer’s
declared alignment_log2 is not consulted; the actual borrowed
pointer is checked directly so that mmap’d or sub-sliced inputs
cannot bypass the check.
§Errors
Returns SectionViewError when the payload cannot be borrowed
as &[T] without copying.
§Performance
This method is O(1) modulo the bounds and alignment checks; it
performs no allocation and no per-element work.