pub trait IntoAscii {
// Required methods
fn digits10(self) -> usize;
fn int_to_bytes(self, buff: &mut [u8]);
// Provided method
fn itoa(&self) -> Vec<u8> ⓘ
where Self: Copy { ... }
}Expand description
This traits converts integers to bytes, and is implemented on all integer types.
The most important method on this trait is IntoAscii::itoa, which is called in a method-like style.
It returns a Vec<u8>, representing the value of self as bytes.
Negative numbers also include a - when converted.
Required Methods§
Sourcefn digits10(self) -> usize
fn digits10(self) -> usize
Returns the size of an integer. This is how many digits the integer has.
Sourcefn int_to_bytes(self, buff: &mut [u8])
fn int_to_bytes(self, buff: &mut [u8])
Writes self into buff.
This function assumes buff has enough space to hold all digits of self. For the number of digits self has, see IntoAscii::digits10.
Provided Methods§
Sourcefn itoa(&self) -> Vec<u8> ⓘwhere
Self: Copy,
fn itoa(&self) -> Vec<u8> ⓘwhere
Self: Copy,
The function performing the convertion from a number to a Vec
§Examples
use byte_num::into_ascii::IntoAscii;
fn main() {
assert_eq!(12345u32.itoa(), [b'1', b'2', b'3', b'4', b'5']);
assert_eq!((-12345i32).itoa(), [b'-', b'1', b'2', b'3', b'4', b'5']);
}