diff --git a/src/re_set.rs b/src/re_set.rs index fc2b61a8ba..cdfc4bffd7 100644 --- a/src/re_set.rs +++ b/src/re_set.rs @@ -207,6 +207,11 @@ impl RegexSet { self.0.regex_strings().len() } + /// Returns `true` if this set contains no regular expressions. + pub fn is_empty(&self) -> bool { + self.0.regex_strings().is_empty() + } + /// Returns the patterns that this set will match on. /// /// This function can be used to determine the pattern for a match. The diff --git a/tests/set.rs b/tests/set.rs index 648feec4be..37fcf8700c 100644 --- a/tests/set.rs +++ b/tests/set.rs @@ -54,3 +54,14 @@ fn get_set_patterns() { let set = regex_set!(&["a", "b"]); assert_eq!(vec!["a", "b"], set.patterns()); } + +#[test] +fn len_and_empty() { + let empty = regex_set!(&[""; 0]); + assert_eq!(empty.len(), 0); + assert!(empty.is_empty()); + + let not_empty = regex_set!(&["ab", "b"]); + assert_eq!(not_empty.len(), 2); + assert!(!not_empty.is_empty()); +}