Helper function to format items with optional truncation
(
config: &LintExecutionConfig,
header: &str,
items: impl Iterator<Item = T>,
o: &mut String,
)
| 211 | |
| 212 | // Helper function to format items with optional truncation |
| 213 | fn format_items<T>( |
| 214 | config: &LintExecutionConfig, |
| 215 | header: &str, |
| 216 | items: impl Iterator<Item = T>, |
| 217 | o: &mut String, |
| 218 | ) -> Result<()> |
| 219 | where |
| 220 | T: Display, |
| 221 | { |
| 222 | let mut items = items.into_iter(); |
| 223 | if config.no_truncate { |
| 224 | let Some(first) = items.next() else { |
| 225 | return Ok(()); |
| 226 | }; |
| 227 | writeln!(o, "{header}:")?; |
| 228 | writeln!(o, " {first}")?; |
| 229 | for item in items { |
| 230 | writeln!(o, " {item}")?; |
| 231 | } |
| 232 | return Ok(()); |
| 233 | } else { |
| 234 | let Some((samples, rest)) = bootc_utils::collect_until(items, DEFAULT_TRUNCATED_OUTPUT) |
| 235 | else { |
| 236 | return Ok(()); |
| 237 | }; |
| 238 | writeln!(o, "{header}:")?; |
| 239 | for item in samples { |
| 240 | writeln!(o, " {item}")?; |
| 241 | } |
| 242 | if rest > 0 { |
| 243 | writeln!(o, " ...and {rest} more")?; |
| 244 | } |
| 245 | } |
| 246 | Ok(()) |
| 247 | } |
| 248 | |
| 249 | // Helper to build a lint error message from multiple sections. |
| 250 | // The closure `build_message_fn` is responsible for calling `format_items` |