Skip to content

Commit

Permalink
fixup! More generic impl of Replacer for closures
Browse files Browse the repository at this point in the history
Added documentation comment on `Replacer` impl for closures.
  • Loading branch information
JanBeh committed Jul 20, 2023
1 parent 43222f2 commit 2c8c8dd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/regex/string.rs
Expand Up @@ -2570,6 +2570,20 @@ impl<'a> Replacer for &'a Cow<'a, str> {
}
}

/// Blanket implementation of `Replacer` for closures.
///
/// This implementation is basically the following, except that the return type
/// `T` may optionally depend on lifetime `'a`.
///
/// ```ignore
/// impl<F, T> Replacer for F
/// where
/// F: for<'a> FnMut(&a Captures<'_>) -> T,
/// T: AsRef<str>, // `T` may also depend on `'a`, which cannot be expressed easily
/// {
/// /* … */
/// }
/// ```
impl<F: for<'a> ReplacerClosure<'a>> Replacer for F {
fn replace_append(&mut self, caps: &Captures<'_>, dst: &mut String) {
dst.push_str((*self)(caps).as_ref());
Expand Down

0 comments on commit 2c8c8dd

Please sign in to comment.