Skip to main content

dry4rust/cli/
ignore_entry_line.rs

1// Copyright (c) 2026 Matjaz Domen Pecan
2// Copyright 2026 Umberto Gotti <umberto.gotti@umbertogotti.dev>
3// Licensed under the MIT License
4// SPDX-License-Identifier: MIT
5
6use std::fmt;
7
8use crate::suppression::ignore_entry::IgnoreEntry;
9
10/// One ignore entry as a single report line.
11///
12/// `ignored` and `cleanup` both list entries and must list them identically,
13/// so the shape lives in one place. `Display` rather than a writer-taking
14/// helper: the line is then a value a test can compare against, without a
15/// buffer in between.
16pub struct IgnoreEntryLine<'a> {
17    entry: &'a IgnoreEntry,
18}
19
20impl<'a> IgnoreEntryLine<'a> {
21    #[must_use]
22    pub const fn new(entry: &'a IgnoreEntry) -> Self {
23        Self { entry }
24    }
25}
26
27impl fmt::Display for IgnoreEntryLine<'_> {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        write!(f, "  {}", self.entry.fingerprint)?;
30        if let Some(reason) = &self.entry.reason {
31            write!(f, " (reason: {reason})")?;
32        }
33        if !self.entry.members.is_empty() {
34            write!(f, " [{}]", self.entry.members.join(", "))?;
35        }
36        Ok(())
37    }
38}