Skip to main content

debug_assert_well_formed

Function debug_assert_well_formed 

Source
pub fn debug_assert_well_formed(runs: &[FormatRun], block_text_len: usize)
Expand description

Debug-only invariant check. Run from debug_assert! callsites in the use cases that mutate format runs. Cheap: O(n) where n is the run count (typically < 100 per block in real prose).

§Invariants

  1. Runs are sorted by byte_start ascending.
  2. Each run has byte_start < byte_end.
  3. Runs are non-overlapping: runs[i].byte_end <= runs[i+1].byte_start.
  4. The last run’s byte_end does not exceed block_text_len.
  5. Adjacent runs with identical format are coalesced (no two consecutive runs satisfy byte_end == next.byte_start && format == next.format).