|
|
|
|
|
by ridiculous_fish
2589 days ago
|
|
RangeInclusive is an interesting API: 1. How does this handle ranges whose length is larger than can be represented in an integer? 2. How does iterating a range work for floats? It looks like it just adds one [1], won't this mean that it will loop forever if the next representable float is +2? 1: https://doc.rust-lang.org/src/core/iter/range.rs.html#297 |
|
https://doc.rust-lang.org/std/iter/trait.Step.html
Thus RangeInclusive<f64> is perfectly valid, but RangeInclusive<f64> cannot be used as an Iterator.
See also the bounds on contains():
https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html...
f64 is PartialOrd<f64>, so a RangeInclusive<f64> can be asked if it contains a specified f64. This definition would also allow one to ask a RangeInclusive<IpAddr> if it contains a specified IpAddr _or_ Ipv4Addr _or_ Ipv6Addr, since IpAddr is PartialOrd<IpAddr>, PartialOrd<Ipv4Addr>, and PartialOrd<Ipv6Addr>.
Any type A which can be compared to any other type B automatically gets RangeInclusive<A>::contains(B). Anything which doesn't can still be a RangeInclusive<A>, it just won't have contains().