私はFlatMap
の項目のすべての可能なペアを作成しようとしています:std :: iter :: FlatMap.clone()は可能ですか?
possible_children.clone().flat_map(|a| possible_children.clone().map(|b| (a,b)))
これを行うためには、FlatMap
構造体はclone
メソッドを実装していることを私はFlatMap
のクローンを作成しようとしていると私は、マニュアルで見ます。しかし、特性境界を満たすFlatMap
を作成することはできないようです。
これは私が取得していますエラーです:F
の両方に拘束されているように見えます
impl<I, U, F> Clone for FlatMap<I, U, F>
where F: Clone, I: Clone, U: Clone + IntoIterator, U::IntoIter: Clone
と
impl<I, U, F> Iterator for FlatMap<I, U, F>
where F: FnMut(I::Item) -> U, I: Iterator, U: IntoIterator
:
error: no method named `clone` found for type `std::iter::FlatMap<std::ops::Range<u16>, _, [[email protected]/main.rs:30:47: 33:27]>` in the current scope
--> src/main.rs:37:66
|
37 | possible_children.clone().flat_map(|a| possible_children.clone().map(|b| (a,b)))
| ^^^^^
|
= note: the method `clone` exists but the following trait bounds were not satisfied: `[[email protected]/main.rs:30:47: 33:27] : std::clone::Clone`
は、私が見るドキュメントを見ますClone
形質及びFnMut
形質が可能であるが、 eを入力してFnMut
とClone
の両方を実装します。
ドキュメントには呼び出すことができないメソッドが存在することがありますので、何か不足しているはずです。
誰かが私に明確にしてもらえますか?
MVCE:
fn main() {
let possible_children = (0..10).flat_map(|x| (0..10).map(|y| (x,y)));
let causes_error = possible_children.clone().flat_map(|a|
possible_children.clone().map(|b| (a,b))
).collect();
println!("{:?}",causes_error);
}
あなたが使用しようとしている 'possible_children'の値は何ですか?そのエラーは何ですか? – Dogbert
possible_childrenの実際の値はやや複雑ですが、これは同じエラーを返します: 'let possible_children =(0..10).flat_map(| x | (0..10).map(| y |(x、y) )) ); ' –