#digits #iterator #integer #numbers #radix

digits_iterator

Iterate over the digits of numbers in an arbitrary radix

1 unstable release

Uses old Rust 2015

0.1.0 Jun 7, 2018

#35 in #digits

Download history 2793/week @ 2024-04-08 3076/week @ 2024-04-15 2895/week @ 2024-04-22 2693/week @ 2024-04-29 2956/week @ 2024-05-06 2849/week @ 2024-05-13 1722/week @ 2024-05-20 1051/week @ 2024-05-27 1635/week @ 2024-06-03 1180/week @ 2024-06-10 1370/week @ 2024-06-17 1539/week @ 2024-06-24 1394/week @ 2024-07-01 1574/week @ 2024-07-08 1741/week @ 2024-07-15 1611/week @ 2024-07-22

6,348 downloads per month
Used in 6 crates (3 directly)

Apache-2.0

11KB
242 lines

Digits Iterator

This crate adds an extension method to the integers that permits to iterate over their digits.

Note that the signed integers will be casted to the corresponding unsigned integers. Do not use this iterator with negative signed integers unless you really want to iterate over the digits of the complement.

To use this extension, add the crate and import its content:

extern crate digits_iterator;
use digits_iterator::*;

Examples

use digits_iterator::*;

let digits: Vec<_> = 2018_u32.digits().collect();
assert_eq!(digits[..], [2, 0, 1, 8]);

let digits: Vec<_> = 0b101010.digits_with_base(2).collect();
assert_eq!(digits[..], [1_u8, 0, 1, 0, 1, 0]);

lib.rs:

This crate adds an extension method to the integers that permits to iterate over their digits.

Note that the signed integers will be casted to the corresponding unsigned integers. Do not use this iterator with negative signed integers unless you really want to iterate over the digits of the complement.

To use this extension, add the crate and import its content:

extern crate digits_iterator;
use digits_iterator::*;

Examples

use digits_iterator::*;

let digits: Vec<_> = 2018_u32.digits().collect();
assert_eq!(digits[..], [2, 0, 1, 8]);

let digits: Vec<_> = 0b101010.digits_with_base(2).collect();
assert_eq!(digits[..], [1_u8, 0, 1, 0, 1, 0]);

No runtime deps