I have a enum wrapping a vector of traits and I am trying to allow
iterating a PointGroup and provide .iter() etc
However, I get the error below that I don't understand.
error[E0599]: the method `next` exists for mutable reference `&mut Vec<Box<(dyn Point + 'static)>>`, but its trait bounds were not satisfied
pub trait Point: Send + Sync + core::fmt::Debug {
fn name(&self) -> String;
}
#[derive(Clone, Debug)]
pub struct MyPoint {
name: String
}
impl MyPoint {
pub fn new(n: &str) -> Box<Self> {
Box::new(MyPoint {name: n.to_string()})
}
}
impl Point for MyPoint {
fn name(&self) -> String {
self.name.to_string()
}
}
pub enum PointGroup {
DefinedPointGroup(Vec<Box<dyn Point>>),
ImplicitPointGroup
}
impl Iterator for PointGroup {
type Item = Box<dyn Point>;
fn next(&mut self) -> Option<Self::Item> {
match self {
PointGroup::DefinedPointGroup(iter) => {
iter.next()
}
PointGroup::ImplicitPointGroup => {
None
}
}
}
}
fn main() {
let points: Vec<Box<dyn Point>> = vec![MyPoint::new("one"), MyPoint::new("two"), MyPoint::new("three")];
let point_group = PointGroup::DefinedPointGroup(points);
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0599]: the method `next` exists for mutable reference `&mut Vec<Box<(dyn Point + 'static)>>`, but its trait bounds were not satisfied
--> src/main.rs:33:22
|
33 | iter.next()
| ^^^^ method cannot be called on `&mut Vec<Box<(dyn Point + 'static)>>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`Vec<Box<(dyn Point + 'static)>>: Iterator`
which is required by `&mut Vec<Box<(dyn Point + 'static)>>: Iterator`
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error