From 48af80b3ab5e30e05cbc758da66ce51e768a029c Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Mon, 16 Dec 2019 12:13:45 +0100 Subject: [PATCH] pxar: match_pattern: impl traits needed for MatchPattern to be comparable. In order to check if two MatchPattern are identical, which will be used to avoid duplicates. Signed-off-by: Christian Ebner --- src/pxar/match_pattern.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pxar/match_pattern.rs b/src/pxar/match_pattern.rs index b4048d87..c5af8f28 100644 --- a/src/pxar/match_pattern.rs +++ b/src/pxar/match_pattern.rs @@ -60,13 +60,28 @@ pub enum MatchType { /// # Ok(()) /// # } /// ``` -#[derive(Clone)] +#[derive(Eq, PartialOrd)] pub struct MatchPattern { pattern: Vec, match_positive: bool, match_dir_only: bool, } +impl std::cmp::PartialEq for MatchPattern { + fn eq(&self, other: &Self) -> bool { + self.pattern == other.pattern + && self.match_positive == other.match_positive + && self.match_dir_only == other.match_dir_only + } +} + +impl std::cmp::Ord for MatchPattern { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + (&self.pattern, &self.match_positive, &self.match_dir_only) + .cmp(&(&other.pattern, &other.match_positive, &other.match_dir_only)) + } +} + impl MatchPattern { /// Read a list of `MatchPattern` from file. /// The file is read line by line (lines terminated by newline character),