rust-lang / regex

An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs.
https://docs.rs/regex
Apache License 2.0
3.52k stars 439 forks source link

expose more knobs #166

Closed BurntSushi closed 7 years ago

BurntSushi commented 8 years ago

Regex currently has two constructors, Regex::new and Regex::with_size_limit. The latter is the same as the former, except it allows one to bound the size of the compiled program. The idea is here to control how much memory is used if a regex is compiled from an untrusted source.

There are other knobs that seem useful for exposing to the user:

There are other knobs that maybe shouldn't be exposed, but could:

It's not clear what, if any, of these things should be exposed. I feel like the knobs that control memory bounds should be accessible to callers, because when you need them, you really need them.

BurntSushi commented 8 years ago

I've given this some thought, and this is where I'm currently at:

  1. There should be a struct with no public fields that permits setting various knobs that can be applied to the construction of a Regex. Knobs can be set using methods. This permits expanding the set of the knobs in the future in an API compatible way.
  2. We should probably start with just two knobs: the existing compile size limit and a new knob that controls how much cache the lazy DFA is allowed to use.
  3. This probably means that Regex will continue to need an alternate constructor, much like how Vec or HashMap have alternate constructors. For example, Regex::with_config or something.