pub struct SdHeaderView<'a> { /* private fields */ }Expand description
Zero-copy view into an SD header payload.
Created by SdHeaderView::parse, which fully validates the SD header,
entries, and options upfront. This makes the entry and option iterators
infallible.
§Validation-proof invariant (candidate “c”)
The type system carries no proof tying the cached entry_count /
option_count to entries_buf / options_buf. parse runs ONE eager
validating walk (draining the lazy L1 DecodeIterators) and caches the
element counts; the infallible accessors (entries
/ options) then re-slice those already-validated
buffers with purpose-built iterators that advance by stride/length WITHOUT
re-running the type/length/transport checks. They TRUST the construction-time
walk. Nothing but this parse-only construction path may populate the
buffers, so the trust holds — the same invariant OptionIter has always
relied on.
Implementations§
Source§impl<'a> SdHeaderView<'a>
impl<'a> SdHeaderView<'a>
Sourcepub fn parse(buf: &'a [u8]) -> Result<Self, Error>
pub fn parse(buf: &'a [u8]) -> Result<Self, Error>
Parse and fully validate an SD header from buf.
Validates:
- Buffer has enough data for flags +
entries_size+ entries +options_size+ options entries_sizeis a multiple ofENTRY_SIZE(16)- All entry type bytes are valid
- All options have valid types and lengths, and IP-bearing options have a recognized transport protocol byte
§Errors
Returns an error if the buffer is too short, entries_size is not a multiple of 16,
any entry type byte is invalid, or any option has an invalid type, length, or
transport protocol byte.
Sourcepub fn entries(&self) -> EntryIter<'a> ⓘ
pub fn entries(&self) -> EntryIter<'a> ⓘ
Returns an infallible iterator over the SD entries.
Re-slices the already-validated entries_buf at the fixed 16-byte
stride; it never re-runs entry-type validation (done once in
parse).
The returned EntryIter is ExactSizeIterator — its length comes
for free from the fixed stride.
Sourcepub fn options(&self) -> OptionIter<'a> ⓘ
pub fn options(&self) -> OptionIter<'a> ⓘ
Returns an infallible iterator over the SD options.
Re-slices the already-validated options_buf by each option’s length
field; it never re-runs option validation (done once in
parse).
Options have no fixed stride, so OptionIter is not itself
ExactSizeIterator; use option_count
for the cached element count.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Returns the number of entries in this SD header.
This is the count cached by the construction-time validating walk.
Sourcepub fn option_count(&self) -> usize
pub fn option_count(&self) -> usize
Returns the number of options in this SD header.
This is the count cached by the construction-time validating walk.
Because options have no fixed stride, this cached count is the analogue
of EntryIter’s free ExactSizeIterator::len for the options section.
Trait Implementations§
Source§impl<'a> Clone for SdHeaderView<'a>
impl<'a> Clone for SdHeaderView<'a>
Source§fn clone(&self) -> SdHeaderView<'a>
fn clone(&self) -> SdHeaderView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more