Skip to content

Commit 20df3d1

Browse files
committed
rust: duplicate filter is a clone-able type
1 parent e71bbfa commit 20df3d1

File tree

4 files changed

+228
-384
lines changed

4 files changed

+228
-384
lines changed

rust/bear/src/modes/semantic.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ impl OutputWriterImpl {
8383
output: PathBuf::from(&args.file_name),
8484
append: args.append,
8585
formatter: output::formatter::EntryFormatter::new(),
86-
duplicate_filter: duplicates.clone(),
86+
filter: output::filter_duplicates::DuplicateFilter::try_from(
87+
duplicates.clone(),
88+
)?,
8789
};
8890
Ok(OutputWriterImpl::Clang(result))
8991
}
@@ -125,7 +127,7 @@ pub(crate) struct ClangOutputWriter {
125127
output: PathBuf,
126128
append: bool,
127129
formatter: output::formatter::EntryFormatter,
128-
duplicate_filter: config::DuplicateFilter,
130+
filter: output::filter_duplicates::DuplicateFilter,
129131
}
130132

131133
impl OutputWriter for ClangOutputWriter {
@@ -149,15 +151,14 @@ impl ClangOutputWriter {
149151
/// Write the entries to the compilation database.
150152
///
151153
/// The entries are written to a temporary file and then renamed to the final output.
152-
/// This guaranties that the output file is always in a consistent state.
154+
/// This ensures that the output file is always in a consistent state.
153155
fn write_into_compilation_db(
154156
&self,
155157
entries: impl Iterator<Item = output::clang::Entry>,
156158
) -> anyhow::Result<()> {
157159
// Filter out the entries as per the configuration.
158-
let mut duplicate_filter: output::filter::EntryPredicate =
159-
From::from(&self.duplicate_filter);
160-
let filtered_entries = entries.filter(move |entry| duplicate_filter(entry));
160+
let mut filter = self.filter.clone();
161+
let filtered_entries = entries.filter(move |entry| filter.unique(entry));
161162
// Write the entries to a temporary file.
162163
self.write_into_temporary_compilation_db(filtered_entries)
163164
.and_then(|temp| {

0 commit comments

Comments
 (0)