dashu_macros/
lib.rs

1// Copyright (c) 2022 Jacob Zhong
2//
3// Licensed under either of
4//
5// * Apache License, Version 2.0
6//   (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
7// * MIT license
8//   (LICENSE-MIT or https://opensource.org/licenses/MIT)
9//
10// at your option.
11//
12// Unless you explicitly state otherwise, any contribution intentionally submitted
13// for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
14// dual licensed as above, without any additional terms or conditions.
15
16//! A macro library for creating big numbers from literals.
17//!
18//! See the documentation of each macro for the usage.
19//!
20//! # Dependency requirement
21//!
22//! Due the fact that the macros expand to plain tokens, and proc macro crates can't
23//! re-export types, it's required to add explicit dependency to the underlying crates
24//! when using the macros. Specifically, you need to add the following crates as dependencies
25//! to your `Cargo.toml`:
26//! * For [ubig!]/[static_ubig!] and [ibig!]/[static_ibig!]: `dashu-int`
27//! * For [fbig!] and [dbig!]: `dashu-int`, `dashu-float`
28//! * For [rbig!]: `dashu-int`, `dashu-ratio`
29//!
30//! If you are using these macros from the `dashu` crate, then it's not necessary to
31//! explicitly adding these dependencies, because the related types are re-exported
32//! by the `dashu` crate.
33
34use proc_macro::TokenStream;
35
36mod parse;
37
38#[proc_macro]
39#[doc = include_str!("../docs/ubig.md")]
40pub fn ubig(input: TokenStream) -> TokenStream {
41    parse::int::parse_integer(false, false, false, input.into()).into()
42}
43
44#[proc_macro]
45#[rustversion::since(1.64)]
46#[doc = include_str!("../docs/static_ubig.md")]
47pub fn static_ubig(input: TokenStream) -> TokenStream {
48    parse::int::parse_integer(false, true, false, input.into()).into()
49}
50
51#[doc(hidden)]
52#[proc_macro]
53pub fn ubig_embedded(input: TokenStream) -> TokenStream {
54    parse::int::parse_integer(false, false, true, input.into()).into()
55}
56
57#[doc(hidden)]
58#[proc_macro]
59#[rustversion::since(1.64)]
60pub fn static_ubig_embedded(input: TokenStream) -> TokenStream {
61    parse::int::parse_integer(false, true, true, input.into()).into()
62}
63
64#[proc_macro]
65#[doc = include_str!("../docs/ibig.md")]
66pub fn ibig(input: TokenStream) -> TokenStream {
67    parse::int::parse_integer(true, false, false, input.into()).into()
68}
69
70#[proc_macro]
71#[rustversion::since(1.64)]
72#[doc = include_str!("../docs/static_ibig.md")]
73pub fn static_ibig(input: TokenStream) -> TokenStream {
74    parse::int::parse_integer(true, true, false, input.into()).into()
75}
76
77#[doc(hidden)]
78#[proc_macro]
79pub fn ibig_embedded(input: TokenStream) -> TokenStream {
80    parse::int::parse_integer(true, false, true, input.into()).into()
81}
82
83#[doc(hidden)]
84#[proc_macro]
85#[rustversion::since(1.64)]
86pub fn static_ibig_embedded(input: TokenStream) -> TokenStream {
87    parse::int::parse_integer(true, true, true, input.into()).into()
88}
89
90#[proc_macro]
91#[doc = include_str!("../docs/fbig.md")]
92pub fn fbig(input: TokenStream) -> TokenStream {
93    parse::float::parse_binary_float(false, false, input.into()).into()
94}
95
96#[proc_macro]
97#[rustversion::since(1.64)]
98#[doc = include_str!("../docs/static_fbig.md")]
99pub fn static_fbig(input: TokenStream) -> TokenStream {
100    parse::float::parse_binary_float(true, false, input.into()).into()
101}
102
103#[doc(hidden)]
104#[proc_macro]
105pub fn fbig_embedded(input: TokenStream) -> TokenStream {
106    parse::float::parse_binary_float(false, true, input.into()).into()
107}
108
109#[doc(hidden)]
110#[proc_macro]
111#[rustversion::since(1.64)]
112pub fn static_fbig_embedded(input: TokenStream) -> TokenStream {
113    parse::float::parse_binary_float(true, true, input.into()).into()
114}
115
116#[proc_macro]
117#[doc = include_str!("../docs/dbig.md")]
118pub fn dbig(input: TokenStream) -> TokenStream {
119    parse::float::parse_decimal_float(false, false, input.into()).into()
120}
121
122#[proc_macro]
123#[rustversion::since(1.64)]
124#[doc = include_str!("../docs/static_dbig.md")]
125pub fn static_dbig(input: TokenStream) -> TokenStream {
126    parse::float::parse_decimal_float(true, false, input.into()).into()
127}
128
129#[doc(hidden)]
130#[proc_macro]
131pub fn dbig_embedded(input: TokenStream) -> TokenStream {
132    parse::float::parse_decimal_float(false, true, input.into()).into()
133}
134
135#[doc(hidden)]
136#[rustversion::since(1.64)]
137#[proc_macro]
138pub fn static_dbig_embedded(input: TokenStream) -> TokenStream {
139    parse::float::parse_decimal_float(true, true, input.into()).into()
140}
141
142#[proc_macro]
143#[doc = include_str!("../docs/rbig.md")]
144pub fn rbig(input: TokenStream) -> TokenStream {
145    parse::ratio::parse_ratio(false, input.into()).into()
146}
147
148#[proc_macro]
149#[rustversion::since(1.64)]
150#[doc = include_str!("../docs/static_rbig.md")]
151pub fn static_rbig(input: TokenStream) -> TokenStream {
152    parse::ratio::parse_static_ratio(false, input.into()).into()
153}
154
155#[doc(hidden)]
156#[proc_macro]
157pub fn rbig_embedded(input: TokenStream) -> TokenStream {
158    parse::ratio::parse_ratio(true, input.into()).into()
159}
160
161#[doc(hidden)]
162#[proc_macro]
163#[rustversion::since(1.64)]
164pub fn static_rbig_embedded(input: TokenStream) -> TokenStream {
165    parse::ratio::parse_static_ratio(true, input.into()).into()
166}