Skip to content

Commit 5040e26

Browse files
sourcefrogBurntSushi
authored andcommitted
api: impl Default for RegexSet
This is justified by the fact that a RegexSet is, after all, a set. And a set has a very obvious default value: the empty set. Plus, this is exactly what you get by passing a default `Vec` or an empty iterator to the `RegexSet::new` constructor. We specifically do not add a `Default` impl for Regex because it has no obvious default value. Fixes #905, Closes #906
1 parent 8c9591a commit 5040e26

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/re_set.rs

+6
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ impl RegexSet {
289289
}
290290
}
291291

292+
impl Default for RegexSet {
293+
fn default() -> Self {
294+
RegexSet::empty()
295+
}
296+
}
297+
292298
/// A set of matches returned by a regex set.
293299
#[derive(Clone, Debug)]
294300
pub struct SetMatches {

tests/set.rs

+7
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@ fn len_and_empty() {
6565
assert_eq!(not_empty.len(), 2);
6666
assert!(!not_empty.is_empty());
6767
}
68+
69+
#[test]
70+
fn default_set_is_empty() {
71+
let set: regex::bytes::RegexSet = Default::default();
72+
assert_eq!(set.len(), 0);
73+
assert!(set.is_empty());
74+
}

0 commit comments

Comments
 (0)