我有一些代码尝试运行匹配,其中每个分支都可以返回不同的类型,但所有这些类型都实现了Iterator<Item=usize>
.
let found: Iterator<Item = usize> = match requirements {
Requirements::A => MatchingAs { ainternals: [] },
Requirements::B => MatchingBs { binternals: [] },
Requirements::C => MatchingCs { cinternals: [] },
};
return found.any(|m| m == 1)
...在哪里MatchingAs
,,MatchingBs
和MatchingCs
所有impl
std::iter::Iterator<Item = usize>
。
我正在碰壁,因为Iterator
它没有尺寸:
| the trait `std::marker::Sized` is not implemented for `std::iter::Iterator<Item=usize>`
有没有一种好的方法让匹配臂返回具有共享特征的对象,然后(仅)依赖于该特征来处理结果?