From 1b08a568966d2f554a6cadb2868aec5645316477 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 21 Sep 2022 10:38:17 -0700 Subject: [PATCH] impl Default for RegexSet Fixes #905 --- src/re_set.rs | 6 ++++++ tests/set.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/re_set.rs b/src/re_set.rs index a6d886d761..92d475f7b0 100644 --- a/src/re_set.rs +++ b/src/re_set.rs @@ -289,6 +289,12 @@ impl RegexSet { } } +impl Default for RegexSet { + fn default() -> Self { + RegexSet::empty() + } +} + /// A set of matches returned by a regex set. #[derive(Clone, Debug)] pub struct SetMatches { diff --git a/tests/set.rs b/tests/set.rs index 37fcf8700c..d1144d6623 100644 --- a/tests/set.rs +++ b/tests/set.rs @@ -65,3 +65,10 @@ fn len_and_empty() { assert_eq!(not_empty.len(), 2); assert!(!not_empty.is_empty()); } + +#[test] +fn default_set_is_empty() { + let set: regex::bytes::RegexSet = Default::default(); + assert_eq!(set.len(), 0); + assert!(set.is_empty()); +}