Skip to content

crate that allows you to iterate over digits of unsigned integers

Notifications You must be signed in to change notification settings

17steen/rust_digit_iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

digit-iterator

Simple library allowing you to quickly iterate over digits of unsigned integers.

Calling as_digits::<BASE>() results in an Iterator, any function implementing Iterator will then be available.

Getting the sum:
let n = 123;
let digit_sum = n.as_digits::<10>().sum(); 
assert_eq!(digit_sum, 6);
Placing them in a vector:
let n = 0xBABE;
let digits = n.as_digits::<16>().collect_vec();
//notice the inverted order
assert_eq!(digits, vec![0xE, 0xB, 0xA, 0xB]);

About

crate that allows you to iterate over digits of unsigned integers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages