Trait numtoa::NumToA

source ·
pub trait NumToA<T> {
    // Required methods
    fn numtoa(self, base: T, string: &mut [u8]) -> usize;
    fn numtoa_str(self, base: T, buf: &mut [u8; 20]) -> &str;
}
Expand description

Converts a number into a string representation, storing the conversion into a mutable byte slice.

Required Methods§

source

fn numtoa(self, base: T, string: &mut [u8]) -> usize

Given a base for encoding and a mutable byte slice, write the number into the byte slice and return the indice where the inner string begins. The inner string can be extracted by slicing the byte slice from that indice.

§Panics

If the supplied buffer is smaller than the number of bytes needed to write the integer, this will panic. On debug builds, this function will perform a check on base 10 conversions to ensure that the input array is large enough to hold the largest possible value in digits.

§Example
use numtoa::NumToA;
use std::io::{self, Write};

let stdout = io::stdout();
let stdout = &mut io::stdout();

let mut buffer = [0u8; 20];
let number = 15325;
let start_indice = number.numtoa(10, &mut buffer);
let _ = stdout.write(&buffer[start_indice..]);
assert_eq!(&buffer[start_indice..], b"15325");
source

fn numtoa_str(self, base: T, buf: &mut [u8; 20]) -> &str

Convenience method for quickly getting a string from the input’s array buffer.

Implementations on Foreign Types§

source§

impl NumToA<i8> for i8

source§

fn numtoa(self, base: i8, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: Self, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<i16> for i16

source§

fn numtoa(self, base: i16, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: i16, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<i32> for i32

source§

fn numtoa(self, base: i32, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: i32, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<i64> for i64

source§

fn numtoa(self, base: i64, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: i64, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<isize> for isize

source§

fn numtoa(self, base: isize, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: isize, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<u8> for u8

source§

fn numtoa(self, base: u8, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: Self, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<u16> for u16

source§

fn numtoa(self, base: u16, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: u16, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<u32> for u32

source§

fn numtoa(self, base: u32, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: u32, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<u64> for u64

source§

fn numtoa(self, base: u64, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: u64, buf: &mut [u8; 20]) -> &str

source§

impl NumToA<usize> for usize

source§

fn numtoa(self, base: usize, string: &mut [u8]) -> usize

source§

fn numtoa_str(self, base: usize, buf: &mut [u8; 20]) -> &str

Implementors§