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
// Copyright © 2020 Alexandra Frydl
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//! Proc macros for [af-core](https://docs.rs/af-core/0.1).

mod attr_future_boxed;
mod attr_main;
mod attr_test_main;
mod prelude;

/// Modifies an `async` function to return a `Box<dyn Future + Send>`.
#[proc_macro_attribute]
pub fn future_boxed(
  _: proc_macro::TokenStream,
  item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
  attr_future_boxed::run(item, true)
}

/// Modifies an `async` function to return a `Box<dyn Future>`.
#[proc_macro_attribute]
pub fn future_boxed_local(
  _: proc_macro::TokenStream,
  item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
  attr_future_boxed::run(item, false)
}

/// Defines an async main function for an `af-core` application.
#[proc_macro_attribute]
pub fn main(_: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
  attr_main::run(item)
}

/// Defines a main function for an `af_core::test` suite.
#[proc_macro_attribute]
pub fn test_main(
  _: proc_macro::TokenStream,
  item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
  attr_test_main::run(item)
}