gpt4 book ai didi

string - 当提供的输入是字符串引用时,str::contains 不起作用

转载 作者:行者123 更新时间:2023-11-29 08:26:38 25 4
gpt4 key购买 nike

use std::collections::HashSet;

fn character_count(needles: &HashSet<char>, needle_type: &str, input: &str) -> i32 {
for needle in needles {
let mut needle_custom;

if needle_type == "double" {
needle_custom = needle.to_string() + &needle.to_string();
} else {
needle_custom = needle.to_string() + &needle.to_string() + &needle.to_string();
}

if input.contains(needle_custom) {
println!("found needle {:?}", needle_custom);
}
}

return 1;
}
error[E0277]: expected a `std::ops::FnMut<(char,)>` closure, found `std::string::String`
--> src/lib.rs:13:18
|
13 | if input.contains(needle_custom) {
| ^^^^^^^^ expected an `FnMut<(char,)>` closure, found `std::string::String`
|
= help: 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`

如果我将 needle_custom 替换为 "test",代码就可以工作。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com