# HG changeset patch # User Raphaël Gomès # Date 1657533553 -7200 # Node ID e8481625c582323cea98b0272e5724decb4b68ba # Parent ffd4b1f1c9cb4a96dd7b8144c3b8299a0c3ac5d8 rust: add Debug constraint to Matcher trait This makes sure we can easily debug which Matcher we're looking at when using trait objects, and is just generally useful. Effort to make the debugging output nicer has been kept to a minimum, please feel free to improve. diff -r ffd4b1f1c9cb -r e8481625c582 rust/hg-core/src/matchers.rs --- a/rust/hg-core/src/matchers.rs Tue Jul 19 15:37:45 2022 +0200 +++ b/rust/hg-core/src/matchers.rs Mon Jul 11 11:59:13 2022 +0200 @@ -46,7 +46,7 @@ Recursive, } -pub trait Matcher { +pub trait Matcher: core::fmt::Debug { /// Explicitly listed files fn file_set(&self) -> Option<&HashSet>; /// Returns whether `filename` is in `file_set` @@ -283,6 +283,18 @@ parents: HashSet, } +impl core::fmt::Debug for IncludeMatcher<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("IncludeMatcher") + .field("patterns", &String::from_utf8_lossy(&self.patterns)) + .field("prefix", &self.prefix) + .field("roots", &self.roots) + .field("dirs", &self.dirs) + .field("parents", &self.parents) + .finish() + } +} + impl<'a> Matcher for IncludeMatcher<'a> { fn file_set(&self) -> Option<&HashSet> { None @@ -330,6 +342,7 @@ } /// The union of multiple matchers. Will match if any of the matchers match. +#[derive(Debug)] pub struct UnionMatcher { matchers: Vec>, } @@ -393,6 +406,7 @@ } } +#[derive(Debug)] pub struct IntersectionMatcher { m1: Box, m2: Box, @@ -474,6 +488,7 @@ } } +#[derive(Debug)] pub struct DifferenceMatcher { base: Box, excluded: Box,