pub trait ToDigits{
// Provided method
fn to_digits(&self) -> Vec<i8> { ... }
}Provided Methods§
Sourcefn to_digits(&self) -> Vec<i8>
fn to_digits(&self) -> Vec<i8>
Converts integer to Vec<i8> of its digits (base 10).
§Example
Basic usage:
use num_digitize::ToDigits;
let number: u8 = 12;
let vector: Vec<i8> = vec![1, 2];
assert_eq!(number.to_digits(), vector);Negative numbers return all the digits negative Vec<u8>:
use num_digitize::ToDigits;
let number = -12;
assert_eq!(number.to_digits(), vec![-1, -2]);Reason for this is mathematically you can easily add these back to the original number like so:
-123 -> [-1, -2, -3]
(-1 * 10^2) + (-2 * 10^1) + (-3 * 10^0) = -123Or with FromDigits trait.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.