https://github.com/pacman82/atoi-rs
Parse integers directly from `[u8]` slices in safe code
https://github.com/pacman82/atoi-rs
Last synced: 2 months ago
JSON representation
Parse integers directly from `[u8]` slices in safe code
- Host: GitHub
- URL: https://github.com/pacman82/atoi-rs
- Owner: pacman82
- License: mit
- Created: 2017-06-29T00:19:14.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2023-12-24T14:51:52.000Z (over 1 year ago)
- Last Synced: 2024-10-29T12:05:54.985Z (7 months ago)
- Language: Rust
- Size: 44.9 KB
- Stars: 53
- Watchers: 5
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
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
```rust
use atoi::atoi;
assert_eq!(Some(42), atoi::(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:```rust
use atoi::FromRadix10;/// Return the parsed integer and remaining slice if successful.
fn atoi_with_rest(text: &[u8]) -> Option<(&[u8], I)> {
match I::from_radix_10(text) {
(_, 0) => None,
(n, used) => Some((&text[used..], n)),
}
}
```This [crate](https://www.crates.io/crates/atoi) has more to offer! Check out the full documentation
at [docs.rs](https://docs.rs/atoi).