クイック文字列検索にを使用したいのですが、コンパイラ エラーなしでHashSet
文字列変数を に渡す方法が見つからないようです。contains
refs = HashSet::new();
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures| {
if caps.len() == 2 {
refs.insert(caps.at(2).unwrap());
}
caps.at(1).unwrap().to_owned()
});
let out = ref_regex.replace_all(&first_pass, |caps: &Captures| {
let capture = caps.at(1).unwrap().to_owned();
// only remove if we've seen it before
if refs.contains(capture) {
return "".to_string();
}
capture
});
これにより、次のエラーが発生します。
src/bin/remove_links.rs:30:26: 30:33 error: mismatched types [E0308]
src/bin/remove_links.rs:30 if refs.contains(capture) {
^~~~~~~
src/bin/remove_links.rs:30:26: 30:33 help: run `rustc --explain E0308` to see a detailed explanation
src/bin/remove_links.rs:30:26: 30:33 note: expected type `&_`
src/bin/remove_links.rs:30:26: 30:33 note: found type `std::string::String`
私が試したら
refs.contains(&capture)
それから私は得る
src/bin/remove_links.rs:30:17: 30:25 error: the trait bound `&str: std::borrow::Borrow<std::string::String>` is not satisfied [E0277]
src/bin/remove_links.rs:30 if refs.contains(&capture) {
^~~~~~~~
私は困惑しています、ある種の型キャストを行う必要がありますか?