【发布时间】:2017-06-01 22:47:41
【问题描述】:
我有一些代码尝试运行每个分支可以返回不同类型的匹配,但是所有这些类型都实现了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>`
有没有一种好的方法可以让匹配臂返回具有共享特征的对象,然后(仅)依赖于该特征来处理结果?
【问题讨论】:
-
请解释为什么这不是Correct way to return an Iterator?的副本
标签: rust matching traits trait-objects