1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#![doc(hidden)]
use crate::options::Options;
use crate::parse::ParseInteger;
use lexical_util::format::{NumberFormat, STANDARD};
use lexical_util::{from_lexical, from_lexical_with_options};
macro_rules! integer_from_lexical {
($($t:ident $unsigned:ident $(, #[$meta:meta])? ; )*) => ($(
impl FromLexical for $t {
$(#[$meta:meta])?
#[cfg_attr(not(feature = "compact"), inline)]
fn from_lexical(bytes: &[u8]) -> lexical_util::result::Result<Self>
{
Self::parse_complete::<$unsigned, STANDARD>(bytes)
}
$(#[$meta:meta])?
#[cfg_attr(not(feature = "compact"), inline)]
fn from_lexical_partial(
bytes: &[u8],
) -> lexical_util::result::Result<(Self, usize)>
{
Self::parse_partial::<$unsigned, STANDARD>(bytes)
}
}
impl FromLexicalWithOptions for $t {
type Options = Options;
$(#[$meta:meta])?
#[cfg_attr(not(feature = "compact"), inline)]
fn from_lexical_with_options<const FORMAT: u128>(
bytes: &[u8],
_: &Self::Options,
) -> lexical_util::result::Result<Self>
{
let format = NumberFormat::<{ FORMAT }> {};
if !format.is_valid() {
return Err(format.error());
}
Self::parse_complete::<$unsigned, FORMAT>(bytes)
}
$(#[$meta:meta])?
#[cfg_attr(not(feature = "compact"), inline)]
fn from_lexical_partial_with_options<const FORMAT: u128>(
bytes: &[u8],
_: &Self::Options,
) -> lexical_util::result::Result<(Self, usize)>
{
let format = NumberFormat::<{ FORMAT }> {};
if !format.is_valid() {
return Err(format.error());
}
Self::parse_partial::<$unsigned, FORMAT>(bytes)
}
}
)*)
}
from_lexical! {}
from_lexical_with_options! {}
integer_from_lexical! {
u8 u8 ;
u16 u16 ;
u32 u32 ;
u64 u64 ;
u128 u128 ;
usize usize ;
i8 u8 ;
i16 u16 ;
i32 u32 ;
i64 u64 ;
i128 u128 ;
isize usize ;
}