1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-01-08 13:23:34 +02:00

Implement Hash for Glob, and re-implement PartialEq using only non-redundant fields.

This commit is contained in:
Stu Hood 2017-01-22 18:15:26 -08:00 committed by Andrew Gallant
parent d825648b86
commit cf750a190f

View File

@ -1,5 +1,6 @@
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use std::fmt; use std::fmt;
use std::hash;
use std::iter; use std::iter;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::path::{Path, is_separator}; 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 /// It cannot be used directly to match file paths, but it can be converted
/// to a regular expression string or a matcher. /// to a regular expression string or a matcher.
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq)]
pub struct Glob { pub struct Glob {
glob: String, glob: String,
re: String, re: String,
@ -84,6 +85,19 @@ pub struct Glob {
tokens: Tokens, 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 { impl fmt::Display for Glob {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.glob.fmt(f) self.glob.fmt(f)
@ -173,7 +187,7 @@ pub struct GlobBuilder<'a> {
opts: GlobOptions, opts: GlobOptions,
} }
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
struct GlobOptions { struct GlobOptions {
/// Whether to match case insensitively. /// Whether to match case insensitively.
case_insensitive: bool, case_insensitive: bool,