In std::ops
, we have the RangeBounds
trait, which provides the methods that return the start and end bounds of all built-in range types.
let range = 10..20;
let bound = range.start_bound();
println!("{:?}", bound); // Included(10)
let range = ..20;
let bound = range.start_bound();
println!("{:?}", bound); // Unbounded
But RangeFull
, despite also implementing RangeBounds
, yields an error.
let range = ..;
let bound = range.start_bound(); // cannot infer type for type parameter `T`
println!("{:?}", bound);
It seems that the compiler needs to know the explicit type of T
for the Bound<&T>
that start_bound
returns.
However, RangeFull
has no associated type parameter, and its implementation of RangeBounds
returns Bound::Unbounded
for both methods.
Is there a way to get the start_bound
or end_bound
for a RangeFull
instance?
For context, I encountered this issue when writing a generic function that would print the bounds for any range instance, using RangeBounds
as the generic type bound.