Hacker News new | ask | show | jobs
by tatterdemalion 3679 days ago
Ranges are used in a lot of places in Rust (over sequential collections, for example). Bit operations are used to engage with low level system APIs like this or for modular arithmetic, which is not common in Rust. As A Rust user, I absolutely know what a range is, and find the `set_range` function very intuitive. I have to drop into messing around with bitwise AND only rarely, and as someone who only wrote a small amount of C before Rust, it is always an exhausting effort.
1 comments

And I find the bit manipulations easier to grok (then again, I know several different assembly languages and have been programming in C for years).

As for the bit ranges, it looks backwards to me, since bits are normally numbered high to low. I would find it easier to read if it read:

    self.0.set_range(3..0, stack_index);
I can "see" that much easier.
Well, Rust supports both bitwise manipulations and a range-based interface, so people from various backgrounds can use whichever they find more natural. :-)
Agreed, definitely should go high to low.