Coverage Report

Created: 2025-07-01 06:19

/src/rust-lexical/lexical-write-float/src/api.rs
Line
Count
Source (jump to first uncovered line)
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
#[cfg(feature = "f16")]
8
use lexical_util::f16::f16;
9
use lexical_util::format::STANDARD;
10
use lexical_util::{to_lexical, to_lexical_with_options};
11
12
use crate::options::Options;
13
use crate::write::WriteFloat;
14
15
// API
16
17
const DEFAULT_OPTIONS: Options = Options::new();
18
19
// Implement `ToLexical` for numeric type.
20
macro_rules! float_to_lexical {
21
    ($($t:tt ; )*) => ($(
22
        impl ToLexical for $t {
23
            #[cfg_attr(not(feature = "compact"), inline)]
24
1.93k
            fn to_lexical(self, bytes: &mut [u8])
25
1.93k
                -> &mut [u8]
26
1.93k
            {
27
1.93k
                let count = self.write_float::<{ STANDARD }>(bytes, &DEFAULT_OPTIONS);
28
1.93k
                &mut bytes[..count]
29
1.93k
            }
<f32 as lexical_write_float::api::ToLexical>::to_lexical
Line
Count
Source
24
629
            fn to_lexical(self, bytes: &mut [u8])
25
629
                -> &mut [u8]
26
629
            {
27
629
                let count = self.write_float::<{ STANDARD }>(bytes, &DEFAULT_OPTIONS);
28
629
                &mut bytes[..count]
29
629
            }
Unexecuted instantiation: <f32 as lexical_write_float::api::ToLexical>::to_lexical
Unexecuted instantiation: <f64 as lexical_write_float::api::ToLexical>::to_lexical
<f64 as lexical_write_float::api::ToLexical>::to_lexical
Line
Count
Source
24
1.30k
            fn to_lexical(self, bytes: &mut [u8])
25
1.30k
                -> &mut [u8]
26
1.30k
            {
27
1.30k
                let count = self.write_float::<{ STANDARD }>(bytes, &DEFAULT_OPTIONS);
28
1.30k
                &mut bytes[..count]
29
1.30k
            }
30
        }
31
32
        impl ToLexicalWithOptions for $t {
33
            type Options = Options;
34
            #[cfg_attr(not(feature = "compact"), inline)]
35
0
            fn to_lexical_with_options<'a, const FORMAT: u128>(
36
0
                self,
37
0
                bytes: &'a mut [u8],
38
0
                options: &Self::Options,
39
0
            ) -> &'a mut [u8]
40
0
            {
41
0
                let count = self.write_float::<{ FORMAT }>(bytes, &options);
42
0
                &mut bytes[..count]
43
0
            }
Unexecuted instantiation: <f32 as lexical_write_float::api::ToLexicalWithOptions>::to_lexical_with_options::<_>
Unexecuted instantiation: <f64 as lexical_write_float::api::ToLexicalWithOptions>::to_lexical_with_options::<_>
44
        }
45
    )*)
46
}
47
48
to_lexical!("lexical_write_float", 1.234, f64);
49
to_lexical_with_options!("lexical_write_float", 1.234, f64, Options);
50
float_to_lexical! {
51
    f32 ;
52
    f64 ;
53
}
54
#[cfg(feature = "f16")]
55
float_to_lexical! {
56
    f16 ;
57
    bf16 ;
58
}