Construct RegexSet from Vec<Regex>
Timmmm opened this issue · 3 comments
Hi, would it be easy to add a RegexSet::from_regexes() constructor that builds from an array of Regexs?
Why? I have written a Serde adapter so my config file can have:
#[serde(with = "crate::serde_regex")]
pub regex: Regex,
The user enters a load of those and then I want to match them with RegexSet. Currently I actually have pub regex: String which is fine, but the code is definitely nicer if Serde does the regex compilation (and it can give nicer error messages too).
It would be easy yes, but I'm not going to add it. It would be a very misleading API. It would still have to recompile all of the regexes into a set, but I feel the API would suggest that it's doing something more clever.
You should be able to accept strings and then wire something up with serde's try_from attribute.
Ah I guess since I'm ok with compiling twice I can just use .as_str() on all the pre-compiled regexes. Thanks!
Beware, regex compilation is can be quite expensive.