#iterator #digits #number #integer #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

#4 in #digits

Download history 549/week @ 2021-10-02 486/week @ 2021-10-09 309/week @ 2021-10-16 492/week @ 2021-10-23 540/week @ 2021-10-30 464/week @ 2021-11-06 621/week @ 2021-11-13 450/week @ 2021-11-20 344/week @ 2021-11-27 606/week @ 2021-12-04 439/week @ 2021-12-11 251/week @ 2021-12-18 177/week @ 2021-12-25 308/week @ 2022-01-01 414/week @ 2022-01-08 344/week @ 2022-01-15

1,284 downloads per month
Used in 5 crates (3 directly)

Apache-2.0

10KB
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