#digits #integer #radix #iterator #numbers

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

#37 in #digits

Download history 3171/week @ 2024-09-01 3019/week @ 2024-09-08 2283/week @ 2024-09-15 2461/week @ 2024-09-22 3013/week @ 2024-09-29 3554/week @ 2024-10-06 2838/week @ 2024-10-13 3387/week @ 2024-10-20 4714/week @ 2024-10-27 7892/week @ 2024-11-03 6716/week @ 2024-11-10 6583/week @ 2024-11-17 5544/week @ 2024-11-24 5109/week @ 2024-12-01 5356/week @ 2024-12-08 6673/week @ 2024-12-15

22,790 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