af_core_proc_macros/
lib.rs

1// Copyright © 2020 Alexandra Frydl
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7//! Proc macros for [af-core](https://docs.rs/af-core/0.1).
8
9mod attr_future_boxed;
10mod attr_main;
11mod attr_test_main;
12mod prelude;
13
14/// Modifies an `async` function to return a `Box<dyn Future + Send>`.
15#[proc_macro_attribute]
16pub fn future_boxed(
17  _: proc_macro::TokenStream,
18  item: proc_macro::TokenStream,
19) -> proc_macro::TokenStream {
20  attr_future_boxed::run(item, true)
21}
22
23/// Modifies an `async` function to return a `Box<dyn Future>`.
24#[proc_macro_attribute]
25pub fn future_boxed_local(
26  _: proc_macro::TokenStream,
27  item: proc_macro::TokenStream,
28) -> proc_macro::TokenStream {
29  attr_future_boxed::run(item, false)
30}
31
32/// Defines an async main function for an `af-core` application.
33#[proc_macro_attribute]
34pub fn main(_: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
35  attr_main::run(item)
36}
37
38/// Defines a main function for an `af_core::test` suite.
39#[proc_macro_attribute]
40pub fn test_main(
41  _: proc_macro::TokenStream,
42  item: proc_macro::TokenStream,
43) -> proc_macro::TokenStream {
44  attr_test_main::run(item)
45}