Оverflow 评估需求,Rust Traits
我正在尝试写一个需要内部类型迭代器的特征。迭代应实现迭代器。我遇到了这样的错误“溢出评估需求 str as thereRait> :: iter == _
”,并且无法理解它想要什么。有人可以帮助理解吗?)
pub trait SomeIter {
type Iter where Self::Iter: Iterator;
}
struct NumberIter(u32, u8);
impl Iterator for NumberIter {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
if self.1 == 32 || (self.0 >> self.1) == 0 {
None
} else {
let ret = ((self.0 >> self.1) as u8) & 0xFF;
self.1 += 8;
Some(ret)
}
}
}
impl SomeTrait for str {
type Iter = NumberIter;
}
编译器建议阅读一些示例,但没有类似的东西。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于
where Self::Iter
部分的解析(因为它是递归的),您只需要限制类型:游乐场
The problem is the resolution over the
where Self::Iter
part (because it is recursive), where you just really need to constrain the type:Playground