Skip to content

Commit 2c8c8dd

Browse files
committed
fixup! More generic impl of Replacer for closures
Added documentation comment on `Replacer` impl for closures.
1 parent 43222f2 commit 2c8c8dd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/regex/string.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,20 @@ impl<'a> Replacer for &'a Cow<'a, str> {
25702570
}
25712571
}
25722572

2573+
/// Blanket implementation of `Replacer` for closures.
2574+
///
2575+
/// This implementation is basically the following, except that the return type
2576+
/// `T` may optionally depend on lifetime `'a`.
2577+
///
2578+
/// ```ignore
2579+
/// impl<F, T> Replacer for F
2580+
/// where
2581+
/// F: for<'a> FnMut(&a Captures<'_>) -> T,
2582+
/// T: AsRef<str>, // `T` may also depend on `'a`, which cannot be expressed easily
2583+
/// {
2584+
/// /* … */
2585+
/// }
2586+
/// ```
25732587
impl<F: for<'a> ReplacerClosure<'a>> Replacer for F {
25742588
fn replace_append(&mut self, caps: &Captures<'_>, dst: &mut String) {
25752589
dst.push_str((*self)(caps).as_ref());

0 commit comments

Comments
 (0)