maybe_fut_derive/
lib.rs

1#![crate_name = "maybe_fut_derive"]
2#![crate_type = "lib"]
3
4//! # maybe-fut-derive
5//!
6//! A procedural macro which exposes the async and sync api for a function
7
8#![doc(html_playground_url = "https://play.rust-lang.org")]
9#![doc(
10    html_favicon_url = "https://raw.githubusercontent.com/veeso/maybe-fut/main/assets/images/logo-128.png"
11)]
12#![doc(
13    html_logo_url = "https://raw.githubusercontent.com/veeso/maybe-fut/main/assets/images/logo-500.png"
14)]
15
16mod args;
17mod struct_derive;
18
19use proc_macro::TokenStream;
20
21#[proc_macro_attribute]
22pub fn maybe_fut(attr: TokenStream, item: TokenStream) -> TokenStream {
23    let args = match syn::parse(attr) {
24        Ok(args) => args,
25        Err(err) => {
26            return err.to_compile_error().into();
27        }
28    };
29
30    // check if the item is an impl block for a struct
31    if let Ok(struct_item) = syn::parse::<syn::ItemImpl>(item) {
32        return struct_derive::maybe_fut_struct(args, struct_item);
33    }
34
35    // error
36    syn::Error::new(
37        proc_macro2::Span::call_site(),
38        "maybe_fut can only be used on impl blocks",
39    )
40    .into_compile_error()
41    .into()
42}