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
use proc_macro::TokenStream;
#[proc_macro]
pub fn hexf32(input: TokenStream) -> TokenStream {
let lit = syn::parse_macro_input!(input as syn::LitStr);
match hexf_parse::parse_hexf32(&lit.value(), true) {
Ok(v) => format!("{:?}f32", v)
.parse()
.expect("formatted a f32 literal"),
Err(e) => syn::Error::new(lit.span(), format!("hexf32! failed: {}", e))
.to_compile_error()
.into(),
}
}
#[proc_macro]
pub fn hexf64(input: TokenStream) -> TokenStream {
let lit = syn::parse_macro_input!(input as syn::LitStr);
match hexf_parse::parse_hexf64(&lit.value(), true) {
Ok(v) => format!("{:?}f64", v)
.parse()
.expect("formatted a f64 literal"),
Err(e) => syn::Error::new(lit.span(), format!("hexf64! failed: {}", e))
.to_compile_error()
.into(),
}
}