digitize 0.1.0

Traits for accessing digits of primitive integers & floats
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use std::fmt::Display;

pub trait Digits: Display {
    /// Returns the digits of a primitive integer type,
    /// like a u8, or i16.
    /// The sign is not included in the returned digits.
    fn digits(&self) -> Box<[u32]> {
        unsafe {
            self.to_string()
                .chars()
                .map(|c| c.to_digit(10).unwrap_unchecked())
                .collect()
        }
    }
}