Ranged integers [nightly only]
Note: the library causes ICEs on some Rust toolchains. The current version (0.7.1) was tested on nightly-2023-02-01.
Provides a generic type Ranged<MIN, MAX> representing an integer
within a specified range. It automatically chooses the data size guided by
the range specified (so Ranged<-50, 50> is of 1 byte while
Ranged<-20_000, 100_000> is of 4 bytes) and supports the arithmetic operations
with automatic bound recalculation and range iteration / fixed-size array indexing.
The conversion and arithmetic functions catch the errors such as possible overflow and zero division at compile time.
Example
extern crate ranged_integers;
use *;
// Consider a simple race game. The player rolls a
// die and then moves forward, backward or forward
// with the double speed according to some rules.
// Get a die roll using a standard random number generator
// Calculate where the player must move
// The result fits the range -6..=12
6, 12>