벡터에 조각을 필터 :에있다 할 필요가있는 일의나는 구조체가
fn do_the_thing(foos: &[Foo]) { ... }
부 :
enum Bar {
Bar0,
Bar1,
Bar2
}
struct Foo {
bar: Bar
}
을 나는 FOOS의 조각을받는 함수가 "바"에 대해 같은 값을 가질 슬라이스의 모든 요소에 다른 함수를 호출
fn another_func(foos: &[Foo]) { ... }
내가 이런 식으로 뭔가를 시도 :
를fn do_the_thing(foos: &[Foo]) {
let bar0_foos = foos.iter().filter(|f| f.bar == Bar0);
another_func(&bar0_foos);
}
비극적으로 bar0_foos는 &std::iter::Filter<std::slice::Iter<...>>
입니다. 나는 또한 시도했다 : 여기
fn do_the_thing(foos: &[Foo]) {
let bar0_foos = foos.iter().filter(|f| f.bar == Bar0).collect();
another_func(&bar0_foos);
}
, 나는 std::marker::Sized
만족 아니라고 말했다 해요.
그럼 어떻게해야할까요? 슬라이스가 아닌 다른 걸 가져 가야할까요? Iterator::collect
는 제네릭 형식을 반환하기 때문에