Skip to content
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

the Replacer trait should be parameterized over a lifetime #777

Open
BurntSushi opened this issue May 5, 2021 · 1 comment
Open

the Replacer trait should be parameterized over a lifetime #777

BurntSushi opened this issue May 5, 2021 · 1 comment

Comments

@BurntSushi
Copy link
Member

It turns out that the Replacer trait is a bit more restrictive than it should be. For the closure impl of Replacer, it requires that the closure work for all possible lifetimes. But it's far more useful to be able to provide a closure that works on a specific lifetime. This makes it possible to do things like return a Cow<str> from the closure to avoid an extra alloc.

This problem was originally brought up in #775 by @tpoliaw.

That lead to @sgrif submitting #776 that changes the Replacer trait to be parameterized over a lifetime.

Unfortunately, it's a breaking change, so this will have to wait for regex 2.0.0.

N.B. This is generally an ergonomic problem I think. It is always possible to implement Replacer oneself and do something more optimal. @tpoliaw also provided a work-around using a closure as well, although it's a bit clunky (but perhaps not as clunky as implementing Repalcer).

@JanBeh
Copy link

JanBeh commented Jul 20, 2023

See also #1048, which I think could solve this issue.

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

No branches or pull requests

2 participants