cargo-dry4rust 0.4.0

A cargo subcommand that detects duplicate and near-duplicate code blocks in Rust codebases using AST normalization
Documentation
// Copyright (c) 2026 Matjaz Domen Pecan
// Copyright 2026 Umberto Gotti <umberto.gotti@umbertogotti.dev>
// Licensed under the MIT License
// SPDX-License-Identifier: MIT

use std::fmt::Write as _;
use std::path::Path;

use crate::cli::cli_error::CliResult;
use crate::cli::command_outcome::CommandOutcome;
use crate::cli::ignore_entry_line::IgnoreEntryLine;
use crate::suppression::ignore_file::IgnoreFile;

/// `ignored`: list what the ignore file holds.
pub struct IgnoredCommand<'a> {
    root: &'a Path,
}

impl<'a> IgnoredCommand<'a> {
    #[must_use]
    pub const fn new(root: &'a Path) -> Self {
        Self { root }
    }

    /// Build every ignore entry, or say there are none.
    ///
    /// # Errors
    ///
    /// Never fails; the signature matches its siblings so the dispatcher can
    /// treat every command alike.
    pub fn run(&self) -> CliResult<CommandOutcome> {
        let ignore_file = IgnoreFile::load(self.root);
        let mut out = String::new();
        if ignore_file.ignore.is_empty() {
            let _ = writeln!(out, "No ignored fingerprints.");
            return Ok(CommandOutcome::succeeded(out));
        }
        let _ = writeln!(out, "Ignored fingerprints:");
        for entry in &ignore_file.ignore {
            let _ = writeln!(out, "{}", IgnoreEntryLine::new(entry));
        }
        Ok(CommandOutcome::succeeded(out))
    }
}