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 <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2019-12-16 12:13:45 +01:00 committed by Dietmar Maurer
parent 255bb86030
commit 48af80b3ab

View File

@ -60,13 +60,28 @@ pub enum MatchType {
/// # Ok(())
/// # }
/// ```
#[derive(Clone)]
#[derive(Eq, PartialOrd)]
pub struct MatchPattern {
pattern: Vec<u8>,
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),