lexical_parse_integer/
parse.rs1#![doc(hidden)]
4
5#[cfg(not(feature = "compact"))]
7use crate::algorithm::{algorithm_complete, algorithm_partial};
8#[cfg(feature = "compact")]
9use crate::compact::{algorithm_complete, algorithm_partial};
10
11use lexical_util::num::{Integer, UnsignedInteger};
12use lexical_util::result::Result;
13
14pub trait ParseInteger: Integer {
16 #[cfg_attr(not(feature = "compact"), inline(always))]
18 fn parse_complete<Unsigned: UnsignedInteger, const FORMAT: u128>(bytes: &[u8]) -> Result<Self> {
19 algorithm_complete::<_, Unsigned, { FORMAT }>(bytes)
20 }
21
22 #[cfg_attr(not(feature = "compact"), inline(always))]
24 fn parse_partial<Unsigned: UnsignedInteger, const FORMAT: u128>(
25 bytes: &[u8],
26 ) -> Result<(Self, usize)> {
27 algorithm_partial::<_, Unsigned, { FORMAT }>(bytes)
28 }
29}
30
31macro_rules! parse_integer_impl {
32 ($($t:ty)*) => ($(
33 impl ParseInteger for $t {}
34 )*)
35}
36
37parse_integer_impl! { u8 u16 u32 u64 u128 usize }
38parse_integer_impl! { i8 i16 i32 i64 i128 isize }