Skip to content

Commit 2ee5e47

Browse files
robjtedeBurntSushi
authored andcommitted
api: add 'empty' constructor to RegexSet
This goes nicely with the new 'is_empty' predicate introduced in the previous commit. It's a bit of a nicer way of building a set with no regexes instead of the weird `&[""; 0]` or something even stranger since the RegexSet::new constructor is polymorphic. Closes #715
1 parent f0263cc commit 2ee5e47

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/re_set.rs

+13
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ impl RegexSet {
9696
RegexSetBuilder::new(exprs).build()
9797
}
9898

99+
/// Create a new empty regex set.
100+
///
101+
/// # Example
102+
///
103+
/// ```rust
104+
/// # use regex::RegexSet;
105+
/// let set = RegexSet::empty();
106+
/// assert!(set.is_empty());
107+
/// ```
108+
pub fn empty() -> RegexSet {
109+
RegexSetBuilder::new(&[""; 0]).build().unwrap()
110+
}
111+
99112
/// Returns true if and only if one of the regexes in this set matches
100113
/// the text given.
101114
///

0 commit comments

Comments
 (0)