pub fn wrap_optimal(text: &str, width: usize) -> KpBreakResultExpand description
Compute optimal line breaks using Knuth-Plass DP.
Given a paragraph of text and a target width, finds the set of line breaks that minimizes total badness (cubic slack penalty).
Runtime is bounded to O(n × [KP_MAX_LOOKAHEAD]) by only considering
line starts within the lookahead window of each break point; for
pathological inputs (more than 1024 words on one line) this degrades
gracefully rather than falling back to a different algorithm.
Whitespace is treated as paragraph glue: leading indentation is dropped and inter-word runs are re-emitted between words on the same line, matching greedy Word-mode defaults.
§Arguments
text- The paragraph to wrap (no embedded newlines expected).width- Target line width in cells.
§Returns
KpBreakResult with optimal lines, total cost, and per-line badness.