Skip to main content

cap_bytes

Function cap_bytes 

Source
pub fn cap_bytes(text: &str, max: usize) -> String
Expand description

Keep whole lines while they fit in max bytes, dropping the rest.

A budget in bytes, unlike one in lines, can fall in the middle of a line — and half a line is worse than no line: a path cut short still reads as a path, and a caller acts on it. So the cut is always at a line ending, and a first line too long to fit yields nothing rather than a fragment.