IntoAscii

Trait IntoAscii 

Source
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§

Source

fn digits10(self) -> usize

Returns the size of an integer. This is how many digits the integer has.

Source

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§

Source

fn itoa(&self) -> Vec<u8>
where Self: Copy,

The function performing the convertion from a number to a Vec, containing the digits of the number.

§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']);
}

Implementations on Foreign Types§

Source§

impl IntoAscii for i8

Source§

fn itoa(&self) -> Vec<u8>
where Self: Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for i16

Source§

fn itoa(&self) -> Vec<u8>
where Self: Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for i32

Source§

fn itoa(&self) -> Vec<u8>
where Self: Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for i64

Source§

fn itoa(&self) -> Vec<u8>
where Self: Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for isize

Source§

fn itoa(&self) -> Vec<u8>
where Self: Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for u8

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for u16

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for u32

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for u64

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl IntoAscii for usize

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl<'a, N> IntoAscii for &'a N
where N: IntoAscii + Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl<'a, N> IntoAscii for &'a mut N
where N: IntoAscii + Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Source§

impl<N> IntoAscii for Box<N>
where N: IntoAscii + Copy,

Source§

fn digits10(self) -> usize

Source§

fn int_to_bytes(self, buff: &mut [u8])

Implementors§