lexical_parse_integer/
parse.rs

1//! Shared trait and methods for parsing integers.
2
3#![doc(hidden)]
4
5// Select the correct back-end.
6use lexical_util::num::Integer;
7use lexical_util::result::Result;
8
9use crate::algorithm::{algorithm_complete, algorithm_partial};
10use crate::Options;
11
12/// Parse integer trait, implemented in terms of the optimized back-end.
13pub trait ParseInteger: Integer {
14    /// Forward complete parser parameters to the backend.
15    #[cfg_attr(not(feature = "compact"), inline(always))]
16    fn parse_complete<const FORMAT: u128>(bytes: &[u8], options: &Options) -> Result<Self> {
17        algorithm_complete::<_, { FORMAT }>(bytes, options)
18    }
19
20    /// Forward partial parser parameters to the backend.
21    #[cfg_attr(not(feature = "compact"), inline(always))]
22    fn parse_partial<const FORMAT: u128>(bytes: &[u8], options: &Options) -> Result<(Self, usize)> {
23        algorithm_partial::<_, { FORMAT }>(bytes, options)
24    }
25}
26
27macro_rules! parse_integer_impl {
28    ($($t:ty)*) => ($(
29        impl ParseInteger for $t {}
30    )*)
31}
32
33parse_integer_impl! { u8 u16 u32 u64 u128 usize }
34parse_integer_impl! { i8 i16 i32 i64 i128 isize }