#ascii-byte #integer #atoi

no-std btoi

Parse integers directly from ASCII byte slices

11 releases

0.5.0 May 29, 2025
0.4.4 Jan 4, 2025
0.4.3 Feb 18, 2023
0.4.2 Feb 16, 2020
0.1.2 Nov 29, 2017

#88 in Parser implementations

Download history 94492/week @ 2025-08-05 85542/week @ 2025-08-12 91825/week @ 2025-08-19 103214/week @ 2025-08-26 99390/week @ 2025-09-02 105714/week @ 2025-09-09 97074/week @ 2025-09-16 101648/week @ 2025-09-23 107286/week @ 2025-09-30 107694/week @ 2025-10-07 109589/week @ 2025-10-14 114152/week @ 2025-10-21 112252/week @ 2025-10-28 120966/week @ 2025-11-04 107281/week @ 2025-11-11 110835/week @ 2025-11-18

470,197 downloads per month
Used in 252 crates (24 directly)

MIT/Apache

24KB
310 lines

btoi

Parse integers from ASCII byte slices.

crates.io docs.rs

Introduction

Provides functions similar to from_str_radix, but is faster when parsing directly from byte slices instead of strings.

Supports #![no_std].

use btoi::btoi;

assert_eq!(Ok(42), btoi(b"42"));
assert_eq!(Ok(-1000), btoi(b"-1000"));

Documentation

Read the documentation

MSRV policy

The minimum supported Rust version is 1.60, matching num_traits, with no intent to ever increase it.

That's because #![feature(int_from_ascii)] in the standard library will hopefully eventually make this crate obsolete for new versions of Rust, and so old versions are the priority.

Changelog

  • 0.5.0
    • Tweak error messages and expose ParseIntegerErrorKind via ParseIntegerError::kind().
  • 0.4.4 (yanked due to unintended MSRV bump)
    • Implement core::error::Error for ParseIntegerError.
  • 0.4.3
    • Use #[track_caller].
  • 0.4.2
    • No longer !#[deny(warnings)], which is is a forwards compability hazard in libraries.
    • Explicit !#[forbid(unsafe_code)].
  • 0.4.1
    • - was parsed as zero, but should have errored. Thanks @wayslog.
  • 0.4.0
    • Change type of radix to u32 (from u8) to mirror the standard library.
    • No need to #[inline] generic functions.
  • 0.3.0
    • New default feature std. Disable for #![no_std] support.
    • Mark functions as #[inline].
  • 0.2.0
    • No longer reexport num-traits.
  • 0.1.3
    • Update to num-traits 0.2 (semver compatible).
  • 0.1.2
    • Fix documentation warnings.
    • Update dependencies.
  • 0.1.1
    • Documentation fixes.
  • 0.1.0
    • Initial release.

License

btoi is dual licensed under the Apache 2.0 and MIT license, at your option.

Dependencies

~145KB