Skip to content

the Replacer trait should be parameterized over a lifetime #777

Open
@BurntSushi

Description

@BurntSushi

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions