Ranged integers [nightly only]
Note: the library relies on the incomplete Rust features:
- It causes ICEson some Rust toolchains,
- The usage may increase the time compilation time heavily.
- The current version (0.10.1) was tested on nightly-2025-06-24.
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. The fixed sized arrays can be
indexed with a ranged integer having the fitting bounds.
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>