gix_macros/lib.rs
1//! A crate of useful macros used in `gix` primarily.
2//!
3//! Note that within `gix-*` crates, monomorphization should never be used for convenience, but only for performance
4//! reasons. And in the latter case, manual denomophization should be considered if the trait in questions isn't called
5//! often enough or measurements indicate that `&dyn Trait` is increasing the runtime. Thus, `gix-*` crates should probably
6//! by default prefer using `&dyn` unless measurements indicate otherwise.
7use proc_macro::TokenStream;
8
9/// Turn async-shaped Rust code into its blocking equivalent by removing `async` and `.await` tokens.
10#[proc_macro_attribute]
11pub fn sync(_attrs: TokenStream, input: TokenStream) -> TokenStream {
12 bisync::sync(input.into()).into()
13}
14
15/// Keep an item unchanged when selecting one side of a shared blocking and async implementation.
16#[proc_macro_attribute]
17pub fn keep(_attrs: TokenStream, input: TokenStream) -> TokenStream {
18 input
19}
20
21/// Remove an item when selecting one side of a shared blocking and async implementation.
22#[proc_macro_attribute]
23pub fn discard(_attrs: TokenStream, _input: TokenStream) -> TokenStream {
24 TokenStream::new()
25}
26
27/// When applied to functions or methods, it will turn it into a wrapper that will immediately call
28/// a de-monomorphized implementation (i.e. one that uses `&dyn Trait`).
29///
30/// That way, the landing-pads for convenience will be as small as possible which then delegate to a single
31/// function or method for implementation.
32///
33/// The parameters using the following traits can be de-monomorphized:
34///
35/// * `Into`
36/// * `AsRef`
37/// * `AsMut`
38#[proc_macro_attribute]
39pub fn momo(_attrs: TokenStream, input: TokenStream) -> TokenStream {
40 momo::inner(input.into()).into()
41}
42
43mod bisync;
44mod momo;