pacman82/atoi-rs

Parse integers directly from `[u8]` slices in safe code

Rust

67

103 commits

updated Sep 24, 2026

See the code

README

atoi-rs

Parse integers directly from [u8] slices in safe code

Reasons to use this crate

Starting from a binary or ascii format you can parse an integer around three times as fast as with the more idiomatic detour over utf8. The crate comes with benchmarks so you can see for yourself.

The FromRadix10Checked trait also provides a way to parse integers very fast and safe, as its implementation only performs checked arithmetics for the one digit that may actually overflow.

Example

Parsing from a slice

use atoi::atoi;
assert_eq!(Some(42), atoi::<u32>(b"42"));

Note that if you want to know how much of the input has been used, you can use the FromRadix10 trait, for example:

use atoi::FromRadix10;

/// Return the parsed integer and remaining slice if successful.
fn atoi_with_rest<I: FromRadix10>(text: &[u8]) -> Option<(&[u8], I)> {
    match I::from_radix_10(text) {
        (_, 0) => None,
        (n, used) => Some((&text[used..], n)),
    }
}

This crate has more to offer! Check out the full documentation at docs.rs.

pacman82/atoi-rs

Parse integers directly from `[u8]` slices in safe code

Rust

67

103 commits

updated Sep 24, 2026

See the code

README

atoi-rs

Parse integers directly from [u8] slices in safe code

Reasons to use this crate

Starting from a binary or ascii format you can parse an integer around three times as fast as with the more idiomatic detour over utf8. The crate comes with benchmarks so you can see for yourself.

The FromRadix10Checked trait also provides a way to parse integers very fast and safe, as its implementation only performs checked arithmetics for the one digit that may actually overflow.

Example

Parsing from a slice

use atoi::atoi;
assert_eq!(Some(42), atoi::<u32>(b"42"));

Note that if you want to know how much of the input has been used, you can use the FromRadix10 trait, for example:

use atoi::FromRadix10;

/// Return the parsed integer and remaining slice if successful.
fn atoi_with_rest<I: FromRadix10>(text: &[u8]) -> Option<(&[u8], I)> {
    match I::from_radix_10(text) {
        (_, 0) => None,
        (n, used) => Some((&text[used..], n)),
    }
}

This crate has more to offer! Check out the full documentation at docs.rs.

Project health

Overall

4.3/10

Maintained

5/10

Code review

0/10
OpenSSF Scorecard

Significant stargazers

Kornel

2,192 followers · starred May 2018

Niklas Fiekas

659 followers · starred Sep 2017

chiri

26 followers · starred Nov 2025