The following code tries to check whether a String contains another String. I get a compiler error when I use the String::contains method. I expect String::contains(String) would work straight out of the box.
What is the correct way to do this in Rust, when the pattern being searched for is not a string literal? I did rustc --explain E0277, and it seems like String does not implement the Pattern trait, is that true?
fn main() { let a = String::from("abcdefgh"); let b = String::from("def"); if a.contains(b) { println!("Contained"); } else { println!("Not contained"); } } The compiler error:
error[E0277]: the trait bound `std::string::String: std::ops::FnMut<(char,)>` is not satisfied --> src/main.rs:6:10 | 6 | if a.contains(b) { | ^^^^^^^^ the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String` | = note: required because of the requirements on the impl of `std::str::pattern::Pattern<'_>` for `std::string::String`
&foo) can be used anywhere an&strcan, so the solution is a trivials_i.contains(&s_i_minus_1). I'm almost certain this is a duplicate of something, althoughstring contains [rust]search doesn't come up with anything immediately applicable.