# HG changeset patch # User Raphaël Gomès # Date 2022-07-11 09:59:13 # 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 --git a/rust/hg-core/src/matchers.rs b/rust/hg-core/src/matchers.rs --- a/rust/hg-core/src/matchers.rs +++ b/rust/hg-core/src/matchers.rs @@ -46,7 +46,7 @@ pub enum VisitChildrenSet { 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 @@ pub struct IncludeMatcher<'a> { 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 @@ impl<'a> Matcher for IncludeMatcher<'a> } /// The union of multiple matchers. Will match if any of the matchers match. +#[derive(Debug)] pub struct UnionMatcher { matchers: Vec>, } @@ -393,6 +406,7 @@ impl UnionMatcher { } } +#[derive(Debug)] pub struct IntersectionMatcher { m1: Box, m2: Box, @@ -474,6 +488,7 @@ impl IntersectionMatcher { } } +#[derive(Debug)] pub struct DifferenceMatcher { base: Box, excluded: Box,