#numbers #convert #itoa #no-alloc

no-std numtoa

Convert numbers into stack-allocated byte arrays

8 unstable releases

Uses old Rust 2015

1.0.0-alpha1 Oct 7, 2025
0.3.1 Jul 7, 2025
0.3.0 Jun 5, 2025
0.2.4 Jun 6, 2021
0.0.7 Jan 31, 2017

#14 in Value formatting

Download history 32265/week @ 2025-08-01 35017/week @ 2025-08-08 31428/week @ 2025-08-15 33773/week @ 2025-08-22 40943/week @ 2025-08-29 39715/week @ 2025-09-05 36809/week @ 2025-09-12 41754/week @ 2025-09-19 42392/week @ 2025-09-26 37199/week @ 2025-10-03 38980/week @ 2025-10-10 41623/week @ 2025-10-17 43411/week @ 2025-10-24 41259/week @ 2025-10-31 40292/week @ 2025-11-07 32193/week @ 2025-11-14

163,620 downloads per month
Used in 807 crates (34 directly)

MIT/Apache

42KB
994 lines

NumToA

#![no_std] Compatible with Zero Heap Allocations

The standard library provides a convenient method of converting numbers into strings, but these strings are heap-allocated. If you have an application which needs to convert large volumes of numbers into strings, but don't want to pay the price of heap allocation, this crate provides an efficient no_std-compatible method of heaplessly converting numbers into their string representations, storing the representation within a reusable byte array.

Supports Multiple Bases

In addition to supporting the standard base 10 conversion, this implementation allows you to select the base of your choice. Therefore, if you want a binary representation, set the base to 2. If you want hexadecimal, set the base to 16.

Supports Const Contexts

This library's API includes const functions that can be used to convert numbers into their string representation at compile time, allowing developers to build smaller & faster executables.

&str Example

use numtoa::NumToA;

let mut buffer = [0u8; 20];
println!("{}", 12345.numtoa_str(10, &mut buffer));
println!("{}", 256652.numtoa_str(10, &mut buffer));

&[u8] Example

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

let stdout = io::stdout();
let mut stdout = stdout.lock();
let mut buffer = [0u8; 20];

let number: u32 = 162392;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");
assert_eq!(number.numtoa(10, &mut buffer), b"162392");

let number: i32 = -6235;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");

let number: i8 = -128;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");

let number: i8 = 53;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");

let number: i16 = -256;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");

let number: i16 = -32768;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");

let number: u64 = 35320842;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");

let number: u64 = 18446744073709551615;
let _ = stdout.write(number.numtoa(10, &mut buffer));
let _ = stdout.write(b"\n");

No runtime deps