app.window_rect().x.step_by(50) fails as iterator
npetrangelo opened this issue · comments
Nathan Petrangelo commented
I am trying to draw a row of ellipses and this for loop will not compile, complaining that the returned pub struct Range<S = scalar::Default>
does not satisfy the Iterator trait bound, even though to my understanding, Iterator is supposed to be implemented for all Ranges.
for i in app.window_rect().x.step_by(50) {
draw.ellipse()
.color(RED)
.x_y(i as f32, -100.0);
}
The rest of my project can be found here.
Nathan Petrangelo commented
I'm not sure there's really an issue with this library or Rust itself, but it is very unclear what the idiomatic way is to loop over this range with a custom step.
Nathan Petrangelo commented
I found a solution, although I wish I could directly cast a Range to a Range.
let w = app.window_rect().w() as i32;
for i in (-w..w).step_by(100) {
draw.ellipse()
.color(RED)
.x_y(i as f32 - 200.0, -100.0);
}