pub struct SnapshotPlan<'a> { /* private fields */ }Expand description
Validated plan that can compute its encoded length and write itself.
SnapshotPlan performs all duplicate-kind, alignment, and count checks
at construction. After construction, encoded_len
and write_into are guaranteed to succeed for any
caller-supplied buffer that is at least encoded_len() bytes long.
§Performance
Construction is O(s^2) for s sections (duplicate-kind check).
encoded_len and write_into are O(s + total payload bytes).
Implementations§
Source§impl<'a> SnapshotPlan<'a>
impl<'a> SnapshotPlan<'a>
Sourcepub fn new(sections: &'a [PendingSection<'a>]) -> Result<Self, PlanError>
pub fn new(sections: &'a [PendingSection<'a>]) -> Result<Self, PlanError>
Sourcepub const fn section_count(&self) -> usize
pub const fn section_count(&self) -> usize
Sourcepub fn encoded_len(&self) -> Result<usize, PlanError>
pub fn encoded_len(&self) -> Result<usize, PlanError>
Computes the total bytes the encoded snapshot will occupy.
§Errors
Returns PlanError::PayloadOverflow when offset arithmetic
exceeds usize or u64 representable values.
§Performance
This function is O(s) for s sections.
Sourcepub fn write_into(&self, out: &mut [u8]) -> Result<usize, PlanError>
pub fn write_into(&self, out: &mut [u8]) -> Result<usize, PlanError>
Writes the encoded snapshot into out and returns the number of
bytes written.
Padding bytes between the section table and each section payload are zero-filled deterministically; the resulting bytes are stable for any logical input.
§Errors
Returns PlanError::BufferTooSmall when out.len() is less than
encoded_len or PlanError::PayloadOverflow
when offset arithmetic overflows during the write walk.
§Performance
This function is O(s + total payload bytes).
Trait Implementations§
Source§impl<'a> Clone for SnapshotPlan<'a>
impl<'a> Clone for SnapshotPlan<'a>
Source§fn clone(&self) -> SnapshotPlan<'a>
fn clone(&self) -> SnapshotPlan<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more