#range #integer #version #dia #ops #sealed #size

yanked dia-range

Ranges for all integers

0.10.0 Jan 7, 2020
0.9.0 Jun 15, 2019
0.8.0 Mar 28, 2019

#6 in #dia

25 downloads per month
Used in bailamos

Custom license

27KB
448 lines

Dia-range




lib.rs:

Dia-range

Ranges for all integers

Project

Features

  • RangeType and Ops traits are implemented for all integer primitive types. So you can use Range on them.
  • Currently only Range is recommended for use. Both RangeType and Ops traits are intended for internal use only. They have to be available publicly for Range to be valid, but they are sealed.

Notes

The crate uses #![no_std] by default. Documentation is built with all features, which include std. If you see some components from std crate, you have to use that feature.

Examples

use dia_range::Range;

// First type i16 is for indexes; second type (u16) is for estimating range size.
// You can ignore second type, the compiler will figure it out.
let mut range: Range<i16, _> = Range::new(50, 100);
assert!(range.contains(&99));
assert!(range.expand(101));
assert!(range.expand(103) == false);
assert!(range.contains(&101));
assert_eq!(range.estimate_size(), 52);

// Merging
assert_eq!(range.merge(&Range::new(100, 150)), Some(Range::new(50, 150)));

No runtime deps

Features