easegress_macros/lib.rs
1// Copyright (c) 2017, MegaEase All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
2
3//!#[easegress_object] is an annotation to generate the `wasm_init` and `wasm_run` functions.
4//! #[easegress_object] can only be used on your struct and the implementation of the Program trait for your struct.
5//!
6//! # Examples
7//! ```
8//! #[easegress_object]
9//! struct Fake;
10//!
11//! #[easegress_object]
12//! impl Program for Fake {
13//! fn new(_param: std::collections::HashMap<String, String>) -> Self {
14//! Self {}
15//! }
16//!
17//! fn run(&self) -> i32 {
18//! 0
19//! }
20//! }
21//! ```
22//!
23//! # Errors
24//! ```
25//! #[easegress_object]
26//! fn fake() {}
27//! ```
28
29mod easegress_object;
30
31extern crate proc_macro;
32use proc_macro::TokenStream;
33
34#[proc_macro_attribute]
35pub fn easegress_object(_attr: TokenStream, item: TokenStream) -> TokenStream {
36 easegress_object::expand_macro(item.into())
37 .unwrap_or_else(syn::Error::into_compile_error)
38 .into()
39}