pub fn encode_snapshot<S: Copy, E: Copy>(
snapshot: S,
output: &mut [u8],
error: E,
encode: for<'encoder> fn(S, &mut SnapshotEncoder<'encoder, E>) -> Result<(), E>,
) -> Result<usize, E>Expand description
Encodes one immutable Copy snapshot after an exact measurement pass.
encode is a function pointer, not a capturing closure. Both passes
therefore receive only the same by-value snapshot. An undersized output is
unchanged. A final compare-only pass checks every emitted byte exactly. If
either later pass violates the measured contract or unwinds, the exact
admitted destination is cleared before the error or unwind leaves this
function.
ยงSnapshot contract
The snapshot and values it references must remain immutable for the whole
call. Do not read clocks, random sources, globals, atomics, cells, or other
interior-mutable state from encode. Exact replay detects observable
drift, but it is not an authorization mechanism for a deliberately
stateful encoder.