Skip to main content

Snapshot

Struct Snapshot 

Source
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>

Source

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.

Source

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.

Source

pub const fn format_major(&self) -> u32

Returns the format major version recorded in the snapshot header.

§Performance

This method is O(1).

Source

pub const fn format_minor(&self) -> u32

Returns the format minor version recorded in the snapshot header.

§Performance

This method is O(1).

Source

pub const fn section_count(&self) -> usize

Returns the number of validated sections.

§Performance

This method is O(1).

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'view> Clone for Snapshot<'view>

Source§

fn clone(&self) -> Snapshot<'view>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'view> Debug for Snapshot<'view>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'view> Copy for Snapshot<'view>

Auto Trait Implementations§

§

impl<'view> Freeze for Snapshot<'view>

§

impl<'view> RefUnwindSafe for Snapshot<'view>

§

impl<'view> Send for Snapshot<'view>

§

impl<'view> Sync for Snapshot<'view>

§

impl<'view> Unpin for Snapshot<'view>

§

impl<'view> UnsafeUnpin for Snapshot<'view>

§

impl<'view> UnwindSafe for Snapshot<'view>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.