diff options
author | Stu Hood <stuhood@twitter.com> | 2017-01-22 18:15:26 -0800 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-02-18 11:46:03 -0500 |
commit | cf750a190fcea9cabe16cd1bef4b21f62929a370 (patch) | |
tree | b5460926cbfa3abfc284d32813aa0cdee524ddf9 /globset | |
parent | d825648b8624ee83a066230e4551d69767477d36 (diff) |
Implement Hash for Glob, and re-implement PartialEq using only non-redundant fields.
Diffstat (limited to 'globset')
-rw-r--r-- | globset/src/glob.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/globset/src/glob.rs b/globset/src/glob.rs index 514e2ede..42d651fd 100644 --- a/globset/src/glob.rs +++ b/globset/src/glob.rs @@ -1,5 +1,6 @@ use std::ffi::{OsStr, OsString}; use std::fmt; +use std::hash; use std::iter; use std::ops::{Deref, DerefMut}; use std::path::{Path, is_separator}; @@ -76,7 +77,7 @@ impl MatchStrategy { /// /// It cannot be used directly to match file paths, but it can be converted /// to a regular expression string or a matcher. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq)] pub struct Glob { glob: String, re: String, @@ -84,6 +85,19 @@ pub struct Glob { tokens: Tokens, } +impl PartialEq for Glob { + fn eq(&self, other: &Glob) -> bool { + self.glob == other.glob && self.opts == other.opts + } +} + +impl hash::Hash for Glob { + fn hash<H: hash::Hasher>(&self, state: &mut H) { + self.glob.hash(state); + self.opts.hash(state); + } +} + impl fmt::Display for Glob { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.glob.fmt(f) @@ -173,7 +187,7 @@ pub struct GlobBuilder<'a> { opts: GlobOptions, } -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] struct GlobOptions { /// Whether to match case insensitively. case_insensitive: bool, |