overflow/
lib.rs

1extern crate proc_macro;
2
3mod transform;
4
5use proc_macro::TokenStream;
6use syn::parse_macro_input;
7
8/// Produces a semantically equivalent expression as the one provided
9/// except that each math call is substituted with the equivalent version
10/// of the `wrapping` API.
11///
12/// For instance, `+` is substituted with a call to `wrapping_add`
13#[proc_macro]
14pub fn wrapping(input: TokenStream) -> TokenStream {
15    let input = parse_macro_input!(input as syn::Expr);
16    let expanded = transform::wrapping::transform_expr(input);
17
18    TokenStream::from(expanded)
19}
20
21/// Produces a semantically equivalent expression as the one provided
22/// except that each math call is substituted with the equivalent version
23/// of the `checked` API.
24///
25/// For instance, `+` is substituted with a call to `checked_add`
26#[proc_macro]
27pub fn checked(input: TokenStream) -> TokenStream {
28    let input = parse_macro_input!(input as syn::Expr);
29    let expanded = transform::checked::transform_expr(input, true);
30
31    TokenStream::from(expanded)
32}
33
34/// Produces a semantically equivalent expression as the one provided
35/// except that each math call is substituted with the equivalent version
36/// of the `overflowing` API.
37///
38/// For instance, `+` is substituted with a call to `overflowing_add`
39#[proc_macro]
40pub fn overflowing(input: TokenStream) -> TokenStream {
41    let input = parse_macro_input!(input as syn::Expr);
42    let expanded = transform::overflowing::transform_expr(input, true);
43
44    TokenStream::from(expanded)
45}