MCPcopy Create free account
hub / github.com/bootc-dev/bootc / format_items

Function format_items

crates/lib/src/lints.rs:213–247  ·  view source on GitHub ↗

Helper function to format items with optional truncation

(
    config: &LintExecutionConfig,
    header: &str,
    items: impl Iterator<Item = T>,
    o: &mut String,
)

Source from the content-addressed store, hash-verified

211
212// Helper function to format items with optional truncation
213fn format_items<T>(
214 config: &LintExecutionConfig,
215 header: &str,
216 items: impl Iterator<Item = T>,
217 o: &mut String,
218) -> Result<()>
219where
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`

Callers 6

check_var_tmpfilesFunction · 0.85
check_sysusersFunction · 0.85

Calls 3

collect_untilFunction · 0.85
into_iterMethod · 0.45
nextMethod · 0.45

Tested by 3