pub struct Snapshot<'view> { /* private fields */ }Expand description
Validated, borrowed handle to a snapshot’s bytes and section table.
A Snapshot is constructed via Snapshot::open (default
ValidationLevel::Layout) or Snapshot::open_with. The handle
itself is Copy and trivially cheap to pass; cloning it does not
re-validate.
For header-only inspection without parsing the section table, use
HeaderOnlySnapshot instead — Snapshot always carries a validated
section table.
§Performance
Open is O(s^2) for s sections at ValidationLevel::Layout due to
duplicate-kind detection, otherwise O(s). Subsequent reads are O(1)
to O(s) per call. No allocation occurs.
Implementations§
Source§impl<'view> Snapshot<'view>
impl<'view> Snapshot<'view>
Sourcepub fn open(bytes: &'view [u8]) -> Result<Self, SnapshotError>
pub fn open(bytes: &'view [u8]) -> Result<Self, SnapshotError>
Opens bytes as a validated snapshot at ValidationLevel::Layout.
§Errors
Returns SnapshotError for any header, section table, or layout
invariant violation.
§Performance
O(s^2) for s section entries.
Sourcepub fn open_with(
bytes: &'view [u8],
level: ValidationLevel,
) -> Result<Self, SnapshotError>
pub fn open_with( bytes: &'view [u8], level: ValidationLevel, ) -> Result<Self, SnapshotError>
Opens bytes as a snapshot validated at the requested level.
level selects between ValidationLevel::SectionTable (per-entry
self-consistency only) and ValidationLevel::Layout (full
payload-bounds and duplicate-kind walk). Header-only validation is
deliberately not selectable here; callers wanting it should use
HeaderOnlySnapshot::open.
§Errors
Returns SnapshotError for any invariant violation visible at
the requested level.
§Performance
O(s) at ValidationLevel::SectionTable, O(s^2) at
ValidationLevel::Layout.
Sourcepub const fn format_major(&self) -> u32
pub const fn format_major(&self) -> u32
Sourcepub const fn format_minor(&self) -> u32
pub const fn format_minor(&self) -> u32
Sourcepub const fn section_count(&self) -> usize
pub const fn section_count(&self) -> usize
Sourcepub fn sections(&self) -> SectionIter<'view> ⓘ
pub fn sections(&self) -> SectionIter<'view> ⓘ
Returns an iterator over all validated sections.
§Performance
Constructing the iterator is O(1); advancing it is O(1) per step.
Sourcepub fn section(&self, kind: u32) -> Option<Section<'view>>
pub fn section(&self, kind: u32) -> Option<Section<'view>>
Returns the section with the given kind, when present.
§Performance
This method is O(s) for s section entries.
Sourcepub fn typed_section<W>(
&self,
kind: u32,
expected_version: u32,
) -> Result<&'view [W::LittleEndianWord], SectionBindError>where
W: SnapshotWidth,
pub fn typed_section<W>(
&self,
kind: u32,
expected_version: u32,
) -> Result<&'view [W::LittleEndianWord], SectionBindError>where
W: SnapshotWidth,
Binds a width-typed section by kind and version in one step.
Looks up the section, checks its version against expected_version, and
borrows the payload as &[W::LittleEndianWord]. This is the single
section-open primitive every layout crate reuses instead of
re-implementing the lookup/version/typed-view sequence with its own error
variants; callers map SectionBindError into their own typed error at
the boundary.
§Errors
Returns SectionBindError::Missing when no section has kind,
SectionBindError::VersionMismatch when the recorded version differs,
and SectionBindError::View when the payload cannot be borrowed as the
requested little-endian word.
§Performance
This method is O(s) for s section entries plus the typed-view checks.