Skip to content

Commit

Permalink
api: add 'empty' constructor to RegexSet
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robjtede authored and BurntSushi committed Oct 12, 2020
1 parent f0263cc commit 2ee5e47
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/re_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ impl RegexSet {
RegexSetBuilder::new(exprs).build()
}

/// Create a new empty regex set.
///
/// # Example
///
/// ```rust
/// # use regex::RegexSet;
/// let set = RegexSet::empty();
/// assert!(set.is_empty());
/// ```
pub fn empty() -> RegexSet {
RegexSetBuilder::new(&[""; 0]).build().unwrap()
}

/// Returns true if and only if one of the regexes in this set matches
/// the text given.
///
Expand Down

0 comments on commit 2ee5e47

Please sign in to comment.