Hi all,
This post is a followup to this one.
I'm trying to create a function that inserts a &str before a Pattern.
#![feature(pattern)]
use std::str::pattern::{Pattern};
fn insert_before<P>(input: &mut String, pattern: P)
where for<'a> P: Pattern<'a>,
{
if let Some(index) = input.find(pattern) {
input.insert_str(index, "|");
}
}
This code compiles, but as soon as I change find
with rfind
I get a compile error :
the trait bound `<P as Pattern<'_>>::Searcher: ReverseSearcher<'_>` is not satisfied
#![feature(pattern)]
use std::str::pattern::{Pattern};
fn insert_before<P>(input: &mut String, pattern: P)
where for<'a> P: Pattern<'a>,
{
if let Some(index) = input.rfind(pattern) {
input.insert_str(index, "|");
}
}
I tried to follow the compiler suggestions like this:
#![feature(pattern)]
use std::str::pattern::{Pattern, ReverseSearcher};
fn insert_before<P>(input: &mut String, pattern: P)
where for<'a> P: Pattern<'a>,
for<'a> <P as Pattern<'a>>::Searcher: ReverseSearcher<'a> // I tried to this bound
{
if let Some(index) = input.rfind(pattern) {
input.insert_str(index, "|");
}
}
But without success:
error[E0277]: the trait bound `for<'a> <_ as Pattern<'a>>::Searcher: ReverseSearcher<'a>` is not satisfied
Is this related to Higher-Ranked Trait Bound like in the previous post ?
How can I satisfy the trait bound ?
Thank you for your help.