@@ -2371,21 +2371,22 @@ impl<'c, 'h> ExactSizeIterator for SubCaptureMatches<'c, 'h> {}
2371
2371
2372
2372
impl < ' c , ' h > core:: iter:: FusedIterator for SubCaptureMatches < ' c , ' h > { }
2373
2373
2374
- /// Trait alias for `FnMut` with one argument, which allows adding a bound
2375
- /// without specifying the closure's return type .
2376
- pub trait GenericFnMut1Arg < Arg >
2374
+ /// If a closure implements this for all `'a`, then it also implements
2375
+ /// [`Replacer`] .
2376
+ pub trait ReplacerClosure < ' a >
2377
2377
where
2378
- Self : FnMut ( Arg ) -> <Self as GenericFnMut1Arg < Arg > >:: Output ,
2378
+ Self : FnMut ( & ' a Captures < ' a > ) -> <Self as ReplacerClosure >:: Output ,
2379
2379
{
2380
- /// Return type of the closure.
2381
- type Output ;
2380
+ /// Return type of the closure (may depend on lifetime `'a`) .
2381
+ type Output : AsRef < str > ;
2382
2382
}
2383
2383
2384
- impl < T : ?Sized , Arg , Ret > GenericFnMut1Arg < Arg > for T
2384
+ impl < ' a , F : ?Sized , O > ReplacerClosure < ' a > for F
2385
2385
where
2386
- T : FnMut ( Arg ) -> Ret ,
2386
+ F : FnMut ( & ' a Captures < ' a > ) -> O ,
2387
+ O : AsRef < str > ,
2387
2388
{
2388
- type Output = Ret ;
2389
+ type Output = O ;
2389
2390
}
2390
2391
2391
2392
/// A trait for types that can be used to replace matches in a haystack.
@@ -2518,11 +2519,7 @@ impl<'a> Replacer for &'a Cow<'a, str> {
2518
2519
}
2519
2520
}
2520
2521
2521
- impl < F > Replacer for F
2522
- where
2523
- F : for < ' a > GenericFnMut1Arg < & ' a Captures < ' a > > ,
2524
- for < ' a > <F as GenericFnMut1Arg < & ' a Captures < ' a > > >:: Output : AsRef < str > ,
2525
- {
2522
+ impl < F : for < ' a > ReplacerClosure < ' a > > Replacer for F {
2526
2523
fn replace_append ( & mut self , caps : & Captures < ' _ > , dst : & mut String ) {
2527
2524
dst. push_str ( ( * self ) ( caps) . as_ref ( ) ) ;
2528
2525
}
0 commit comments