Vendored version of atoi from crates.io
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Markus Klein 1bfd9e35fb
Some checks failed
Build and test / Test & Bench Linux (push) Has been cancelled
add propertytesting for i32
2023-12-24 15:51:51 +01:00
.github automatically test no-std on CI 2022-10-11 18:15:19 +02:00
benches additional benches for i128 2023-10-10 22:32:59 +02:00
src No-std as optional feature 2022-10-11 18:05:41 +02:00
tests add propertytesting for i32 2023-12-24 15:51:51 +01:00
.gitignore ignore .vscode 2017-08-18 04:04:55 +02:00
Cargo.toml add propertytesting for i32 2023-12-24 15:51:51 +01:00
Changelog.md use rust 1.70 2023-10-11 09:45:29 +02:00
CONTRIBUTING.md Create CONTRIBUTING.md 2017-06-30 22:58:53 +02:00
LICENSE Create License 2017-06-29 02:21:26 +02:00
README.md Fix broken example README.md 2023-11-23 18:00:17 +01:00
rust-toolchain.toml use rust 1.70 2023-10-11 09:45:29 +02:00

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.