Crates.io | biscuit-converter |
lib.rs | biscuit-converter |
version | 0.3.0 |
source | src |
created_at | 2024-09-09 13:19:41.159088 |
updated_at | 2024-09-13 13:44:05.097108 |
description | A decimal ASCII parser |
homepage | |
repository | https://github.com/JunbeomL22/biscuit-converter |
max_upload_size | |
id | 1369252 |
size | 760,500 |
biscuit-converter is a decimal integer parser using bitwise operations.
Add this to your Cargo.toml
:
[dependencies]
biscuit-converter = "0.3"
Then, use it in your Rust code:
use biscuit_converter::{Biscuit, error::ParseIntErr};
let val = i32::parse_decimal(b"1234");
assert_eq!(val, Ok(1234));
let val = i32::parse_decimal(b"1234a");
assert_eq!(val, Err(ParseIntErr::NonDecimal));
let val = i32::parse_decimal(b"a1234");
assert_eq!(val, Err(ParseIntErr::NonDecimal));
let val = i32::parse_decimal(b"");
assert_eq!(val, Err(ParseIntErr::Empty));
let val = i32::parse_decimal(b" ");
assert_eq!(val, Err(ParseIntErr::NonDecimal));
let val = i32::parse_decimal(b"2147483647"); // i32::MAX
assert_eq!(val, Ok(2147483647));
let val = i32::parse_decimal(b"2147483648"); // i32::MAX + 1
assert_eq!(val, Err(ParseIntErr::Overflow));
let val = i32::parse_decimal(b"-2147483648"); // i32::MIN
assert_eq!(val, Ok(-2147483648));
let val = i32::parse_decimal(b"-2147483649"); // i32::MIN - 1
assert_eq!(val, Err(ParseIntErr::NegOverflow));
let reading = i32::parse_decimal(b"0000000000000000000000000000000000000123");
assert_eq!(reading, Ok(123));
Comparisons: biscuit
& std
& atoi
Key Features:
biscuit-converter
shows better performance compared to other parsers for unsigned types.Test machine: Ryzen 7 7700 3.8Ghz, rust 1.79
Configurations:
[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
set RUSTFLAGS=-C target-cpu=native && cargo bench
u128
comparisonsi128
comparisonsu64
comparisoni64
comparisonu32
comparisoni32
comparisonThis project is licensed under either of
at your option.
We welcome all kinds of contributions! Whether it's bug reports, feature requests, or code contributions, your input is valuable and appreciated. Feel free to open issues or submit pull requests on our GitHub repository.