Iterating over a range of generic type
问题 I have a trait trait B { type Index: Sized + Copy; fn bounds(&self) -> (Self::Index, Self::Index); } I want to get all the Index es within bounds : fn iterate<T: B>(it: &T) { let (low, high) = it.bounds(); for i in low..high {} } This won't work since there's no constraint that the type T can be "ranged" over, and the compiler says as much: error[E0277]: the trait bound `<T as B>::Index: std::iter::Step` is not satisfied --> src/main.rs:8:5 | 8 | for i in low..high {} | ^^^^^^^^^^^^^^^^^^^^^