Hi,
I have some functions which make more sense to return Range<u64>
over Range<usize>
, mostly because I'm parsing data which I know is going to be the u64
type, and returning usize
means that 32-bit software can't parse 64-bit values correctly, which is... wrong, especially since u64
works on 32-bit platforms.
Currently, I'm using a function similar to:
pub fn as_range_usize<T: TryInto<usize>>(range: Range<T>) -> Result<Range<usize>, T::Error> {
Ok(Range {
start: range.start.try_into()?,
end: range.end.try_into()?,
})
}
However, it would be nice to be able to just do let range: Range<usize> = a_u64_range.try_into()?
. Unfortunately, this isn't possible, due to orphan rules (I think).
I could implement a newtype wrapper of Range, but this is just annoying. Is there:
a) Something I'm missing to do this in a good way, or,
b) Any reason why the traits
impl<T> TryFrom<Range<T>> for Range<usize> where usize: TryFrom<T> { /* impl */ }
// or even the more general
impl<U, V> TryFrom<Range<U>> for Range<V> where V: TryFrom<U> { /* impl */ }
are not implemented on Range
?