4 [![Build Status](https://api.travis-ci.org/dtolnay/itoa.svg?branch=master)](https://travis-ci.org/dtolnay/itoa)
5 [![Latest Version](https://img.shields.io/crates/v/itoa.svg)](https://crates.io/crates/itoa)
6 [![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/itoa)
8 This crate provides fast functions for printing integer primitives to an
9 [`io::Write`] or a [`fmt::Write`]. The implementation comes straight from
10 [libcore] but avoids the performance penalty of going through
13 See also [`dtoa`] for printing floating point primitives.
15 *Version requirement: rustc 1.0+*
17 [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
18 [`fmt::Write`]: https://doc.rust-lang.org/core/fmt/trait.Write.html
19 [libcore]: https://github.com/rust-lang/rust/blob/b8214dc6c6fc20d0a660fb5700dca9ebf51ebe89/src/libcore/fmt/num.rs#L201-L254
20 [`fmt::Formatter`]: https://doc.rust-lang.org/std/fmt/struct.Formatter.html
21 [`dtoa`]: https://github.com/dtolnay/dtoa
30 ## Performance (lower is better)
32 ![performance](https://raw.githubusercontent.com/dtolnay/itoa/master/performance.png)
41 fn demo_itoa_write() -> io::Result<()> {
42 // Write to a vector or other io::Write.
43 let mut buf = Vec::new();
44 itoa::write(&mut buf, 128u64)?;
45 println!("{:?}", buf);
47 // Write to a stack buffer.
48 let mut bytes = [0u8; 20];
49 let n = itoa::write(&mut bytes[..], 128u64)?;
50 println!("{:?}", &bytes[..n]);
55 fn demo_itoa_fmt() -> fmt::Result {
57 let mut s = String::new();
58 itoa::fmt(&mut s, 128u64)?;
65 The function signatures are:
68 fn write<W: io::Write, V: itoa::Integer>(writer: W, value: V) -> io::Result<usize>;
70 fn fmt<W: fmt::Write, V: itoa::Integer>(writer: W, value: V) -> fmt::Result;
73 where `itoa::Integer` is implemented for i8, u8, i16, u16, i32, u32, i64, u64,
74 i128, u128, isize and usize. 128-bit integer support requires rustc 1.26+ and
75 the `i128` feature of this crate enabled.
77 The `write` function is only available when the `std` feature is enabled
78 (default is enabled). The return value gives the number of bytes written.
85 Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
86 2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
92 Unless you explicitly state otherwise, any contribution intentionally submitted
93 for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
94 be dual licensed as above, without any additional terms or conditions.