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.