Rust also allows polymorphic return types.
trait Bounded {
fn min_bound() -> Self;
fn max_bound() -> Self;
}
Which can be used like so. Using type inference. fn add_min_to_set<T:Bounded, S:MutableSet<T>>(set: &mut S) {
set.insert(Bounded::min_bound())
}
Or you can be more explicit let mut i: u8 = Bounded::min_bound();
while i < Bounded::max_bound() { println!("{}", i); i += 1; }
Edit: spacing, s/++/+= 1/