Function
wrap_with_width
(code: &str, width: usize)
Source from the content-addressed store, hash-verified
| 14 | } |
| 15 | |
| 16 | fn wrap_with_width(code: &str, width: usize) -> Vec<String> { |
| 17 | let width = width.max(1); |
| 18 | let opts = WrapOptions::new(width).word_splitter(WordSplitter::NoHyphenation); |
| 19 | code.lines() |
| 20 | .flat_map(|line| { |
| 21 | if line.is_empty() { |
| 22 | vec![String::new()] |
| 23 | } else { |
| 24 | wrap(line, &opts) |
| 25 | .into_iter() |
| 26 | .map(|cow| cow.to_string()) |
| 27 | .collect::<Vec<_>>() |
| 28 | } |
| 29 | }) |
| 30 | .collect() |
| 31 | } |
| 32 | |
| 33 | #[cfg(test)] |
| 34 | mod tests { |