我想要这样的东西:
fn filter_one<'a, T: Int>(input: &'a Vec<T>) -> ??? {
input.iter().filter(|&x| x == Int::one())
}
Run Code Online (Sandbox Code Playgroud)
该函数的返回类型是什么?(我想要返回Iterator)
(我希望这不是太明显,我现在已经尝试了半个小时而且开始感到沮丧:p)
编辑:
编译器给我以下错误:
<anon>:5:1: 7:2 error: the trait `core::kinds::Sized` is not implemented for the type `for<'r> core::ops::Fn(&'r T) -> bool + 'a`
<anon>:5 fn filter_one<'a, T: Int>(input: &'a Vec<T>) -> Filter<&T, Iter<'a, T>, Fn(&T) -> bool>{
<anon>:6 input.iter().filter(|&x| x == Int::one())
<anon>:7 }
<anon>:5:1: 7:2 note: required by `core::iter::Filter`
<anon>:5 fn filter_one<'a, T: Int>(input: &'a Vec<T>) -> Filter<&T, Iter<'a, …
Run Code Online (Sandbox Code Playgroud)