Skip to content

Construct RegexSet from Vec<Regex> #1255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Timmmm opened this issue Mar 5, 2025 · 3 comments
Closed

Construct RegexSet from Vec<Regex> #1255

Timmmm opened this issue Mar 5, 2025 · 3 comments

Comments

@Timmmm
Copy link

Timmmm commented Mar 5, 2025

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).

@BurntSushi
Copy link
Member

BurntSushi commented Mar 5, 2025

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.

@BurntSushi BurntSushi closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2025
@Timmmm
Copy link
Author

Timmmm commented Mar 5, 2025

Ah I guess since I'm ok with compiling twice I can just use .as_str() on all the pre-compiled regexes. Thanks!

@BurntSushi
Copy link
Member

Beware, regex compilation is can be quite expensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants