Crate sum_range

Crate sum_range 

Source
Expand description

This crate provides a trait for calculating the sum of numbers in a range.

The trait is implemented for the following types:

The trait provides three methods:

The methods calculate the sum of the numbers in the range, the sum of the odd numbers in the range, and the sum of the even numbers in the range, respectively.

NOTE: For RangeTo and RangeToInclusive, signed integer types are not supported.

§Examples

use sum_range::SumRange;

assert_eq!((1..11).sum_range(), 55u8);
assert_eq!((0..=12).sum_range(), 78u8);
assert_eq!((-10..12).sum_odd_range(), 11i16);
assert_eq!((-5..=5).sum_even_range(), 0i32);

Traits§

SumRange
A trait for calculating the sum of numbers in a range.