Trait numtoa::NumToA[][src]

pub trait NumToA<T> {
    fn numtoa(self, base: T, string: &mut [u8]) -> &[u8];
fn numtoa_str(self, base: T, buf: &mut [u8]) -> &str; }

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

Required Methods

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();

// Allocate a buffer that will be reused in each iteration.
let mut buffer = [0u8; 20];
 
let number = 15325;
let _ = stdout.write(number.numtoa(10, &mut buffer));
 
let number = 1241;
let _ = stdout.write(number.numtoa(10, &mut buffer));
 
assert_eq!(12345.numtoa(10, &mut buffer), b"12345");

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

Implementors