Coverage Report

Created: 2026-04-29 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/lexical-parse-float-1.0.6/src/api.rs
Line
Count
Source
1
////! Implements the algorithm in terms of the lexical API.
2
3
#![doc(hidden)]
4
5
#[cfg(feature = "f16")]
6
use lexical_util::bf16::bf16;
7
use lexical_util::error::Error;
8
#[cfg(feature = "f16")]
9
use lexical_util::f16::f16;
10
use lexical_util::format::{is_valid_options_punctuation, NumberFormat, STANDARD};
11
use lexical_util::{from_lexical, from_lexical_with_options};
12
13
use crate::options::Options;
14
use crate::parse::ParseFloat;
15
16
// API
17
18
const DEFAULT_OPTIONS: Options = Options::new();
19
20
/// Implement `FromLexical` for numeric type.
21
///
22
/// Need to inline these, otherwise code generation is sub-optimal.
23
/// For some reason, it can't determine some of the const evaluations
24
/// can actually be evaluated at compile-time, which causes major branching
25
/// issues.
26
macro_rules! float_from_lexical {
27
    ($($t:ident)*) => ($(
28
        impl FromLexical for $t {
29
            #[cfg_attr(not(feature = "compact"), inline)]
30
5.67k
            fn from_lexical(bytes: &[u8]) -> lexical_util::result::Result<Self>
31
            {
32
5.67k
                Self::parse_complete::<STANDARD>(bytes, &DEFAULT_OPTIONS)
33
5.67k
            }
<f64 as lexical_parse_float::api::FromLexical>::from_lexical
Line
Count
Source
30
5.67k
            fn from_lexical(bytes: &[u8]) -> lexical_util::result::Result<Self>
31
            {
32
5.67k
                Self::parse_complete::<STANDARD>(bytes, &DEFAULT_OPTIONS)
33
5.67k
            }
Unexecuted instantiation: <f32 as lexical_parse_float::api::FromLexical>::from_lexical
Unexecuted instantiation: <f64 as lexical_parse_float::api::FromLexical>::from_lexical
34
35
            #[cfg_attr(not(feature = "compact"), inline)]
36
0
            fn from_lexical_partial(
37
0
                bytes: &[u8],
38
0
            ) -> lexical_util::result::Result<(Self, usize)>
39
            {
40
0
                Self::parse_partial::<STANDARD>(bytes, &DEFAULT_OPTIONS)
41
0
            }
Unexecuted instantiation: <f32 as lexical_parse_float::api::FromLexical>::from_lexical_partial
Unexecuted instantiation: <f64 as lexical_parse_float::api::FromLexical>::from_lexical_partial
42
        }
43
44
        impl FromLexicalWithOptions for $t {
45
            type Options = Options;
46
47
            #[cfg_attr(not(feature = "compact"), inline)]
48
0
            fn from_lexical_with_options<const FORMAT: u128>(
49
0
                bytes: &[u8],
50
0
                options: &Self::Options,
51
0
            ) -> lexical_util::result::Result<Self>
52
            {
53
0
                let format = NumberFormat::<{ FORMAT }> {};
54
0
                if !format.is_valid() {
55
0
                    return Err(format.error());
56
0
                } else if !is_valid_options_punctuation(FORMAT, options.exponent(), options.decimal_point()) {
57
0
                    return Err(Error::InvalidPunctuation);
58
0
                }
59
0
                Self::parse_complete::<FORMAT>(bytes, options)
60
0
            }
Unexecuted instantiation: <f64 as lexical_parse_float::api::FromLexicalWithOptions>::from_lexical_with_options::<_>
Unexecuted instantiation: <f32 as lexical_parse_float::api::FromLexicalWithOptions>::from_lexical_with_options::<_>
61
62
            #[cfg_attr(not(feature = "compact"), inline)]
63
0
            fn from_lexical_partial_with_options<const FORMAT: u128>(
64
0
                bytes: &[u8],
65
0
                options: &Self::Options,
66
0
            ) -> lexical_util::result::Result<(Self, usize)>
67
            {
68
0
                Self::parse_partial::<FORMAT>(bytes, options)
69
0
            }
Unexecuted instantiation: <f64 as lexical_parse_float::api::FromLexicalWithOptions>::from_lexical_partial_with_options::<_>
Unexecuted instantiation: <f32 as lexical_parse_float::api::FromLexicalWithOptions>::from_lexical_partial_with_options::<_>
70
        }
71
    )*)
72
}
73
74
from_lexical!("lexical_parse_float", 1.234, f64, 5);
75
from_lexical_with_options!("lexical_parse_float", 1.234, f64, 5, Options);
76
float_from_lexical! { f32 f64 }
77
78
#[cfg(feature = "f16")]
79
float_from_lexical! { bf16 f16 }