54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
mod smart_default;
|
|
|
|
use proc_macro::TokenStream;
|
|
use quote::quote;
|
|
use syn::{parse_macro_input, DeriveInput};
|
|
|
|
#[proc_macro_derive(AutoDefault, attributes(default))]
|
|
pub fn derive_auto_default(input: TokenStream) -> TokenStream {
|
|
let input = parse_macro_input!(input as DeriveInput);
|
|
match smart_default::body_impl::impl_my_derive(&input) {
|
|
Ok(output) => output.into(),
|
|
Err(error) => error.to_compile_error().into(),
|
|
}
|
|
}
|
|
|
|
/// Marks async main function as the `PageTop` entry-point.
|
|
///
|
|
/// # Examples
|
|
/// ```
|
|
/// #[pagetop::main]
|
|
/// async fn main() {
|
|
/// async { println!("Hello world"); }.await
|
|
/// }
|
|
/// ```
|
|
#[proc_macro_attribute]
|
|
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
|
let mut output: TokenStream = (quote! {
|
|
#[::pagetop::service::rt::main(system = "::pagetop::service::rt::System")]
|
|
})
|
|
.into();
|
|
|
|
output.extend(item);
|
|
output
|
|
}
|
|
|
|
/// Marks async test functions to use the `PageTop` entry-point.
|
|
///
|
|
/// # Examples
|
|
/// ```
|
|
/// #[pagetop::test]
|
|
/// async fn test() {
|
|
/// assert_eq!(async { "Hello world" }.await, "Hello world");
|
|
/// }
|
|
/// ```
|
|
#[proc_macro_attribute]
|
|
pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
|
let mut output: TokenStream = (quote! {
|
|
#[::pagetop::service::rt::test(system = "::pagetop::service::rt::System")]
|
|
})
|
|
.into();
|
|
|
|
output.extend(item);
|
|
output
|
|
}
|