2 ms·
I'll be honest, it's never even occurred to me to use ranges for anything but iteration. And doing so feels out of scope, at least from the way they were design
by brundolf 5y ago
I'll be honest, it's never even occurred to me to use ranges for anything but iteration. And doing so feels out of scope, at least from the way they were designed in Rust (as the author illustrates).
I don't have any specific knowledge on the design process, but Rust ranges very much feel like they were intended to be "for-loops without manual state management, and also you can use them in iterator chains", with anything beyond that being gravy. It seems like the author is just asking to be frustrated by trying to use them for purposes they were never designed to serve.
And anyway- if the author wants to have Copy-able, instrospectable ranges that can be used to represent arbitrary numeric bounds and just happen to also support iteration, it should be trivial to implement that themselves:
#[derive(Copy, Clone)]
struct Range(i32, i32);
You could even have a `.to_range()` method that converts them into a standard Range. I think the author just needs to adjust their expectations around this particular standard construct.