#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/refcell/decolor/main/etc/logo.png",
html_favicon_url = "https://raw.githubusercontent.com/refcell/decolor/main/etc/favicon.ico",
issue_tracker_base_url = "https://github.com/refcell/decolor/issues/"
)]
#![warn(
missing_debug_implementations,
missing_docs,
unreachable_pub,
rustdoc::all
)]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};
#[proc_macro_attribute]
pub fn decolor(_attr: TokenStream, input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemFn);
let orig_function_body = input.block;
let fn_name = &input.sig.ident;
let orig_return_type = &input.sig.output;
let expanded = quote! {
fn #fn_name() #orig_return_type {
match tokio::runtime::Runtime::new() {
Ok(rt) => rt.block_on(async move {
#orig_function_body
}),
Err(_) => tokio::runtime::Handle::current().block_on(async move {
#orig_function_body
}),
}
}
};
expanded.into()
}