pub fn chunk<F>(
text: &str,
markdown: bool,
fits: F,
) -> impl Iterator<Item = String>Expand description
Lazily splits text using a monotonic fits predicate.
For candidates with the same starting position, fits must remain false as
their length increases. The iterator chooses fitting prefixes when possible;
if even the first character fails, it emits that character to guarantee
progress. Empty input yields one empty segment without consulting fits.
Whole lines are packed greedily. When no complete line fits, the first line is split at a character boundary.
In markdown mode, a whole-line cut that leaves a triple-backtick fence open appends a closing fence and reopens it with the same info string in the next segment. Partial-line cuts do not append a closing fence, so an oversized fenced line can produce segments that do not render independently.
A bounded take can stop the iterator before it scans the entire input.