rings_derive/
lib.rs

1extern crate proc_macro;
2#[macro_use]
3extern crate quote;
4use syn::parse_macro_input;
5use syn::DeriveInput;
6mod derives;
7use proc_macro::TokenStream;
8
9/// If the feature is not "wasm", the macro does nothing; otherwise, it calls wasm_bindgen.
10/// wasm_export does not work for Js Class. To export a class to js,
11/// you should use wasm_bindgen or __wasm_bindgen_class_marker.
12/// ref: <https://docs.rs/wasm-bindgen-macro/0.2.86/src/wasm_bindgen_macro/lib.rs.html#51>
13#[proc_macro_attribute]
14pub fn wasm_export(attr: TokenStream, input: TokenStream) -> TokenStream {
15    if !attr.is_empty() {
16        std::unimplemented!("wasm_export is not ready for attribute case");
17    }
18    #[cfg(feature = "wasm")]
19    return match wasm_bindgen_macro_support::expand(attr.into(), input.into()) {
20        Ok(tokens) => tokens.into(),
21        Err(diagnostic) => (quote! { #diagnostic }).into(),
22    };
23
24    #[cfg(not(feature = "wasm"))]
25    return input;
26}
27
28#[proc_macro_derive(MeasureBehaviour)]
29pub fn impl_measure_behaviour(input: TokenStream) -> TokenStream {
30    let ast = parse_macro_input!(input as DeriveInput);
31    crate::derives::impl_measure_behaviour_traits(&ast).into()
32}
33
34#[proc_macro_derive(JudgeConnection)]
35pub fn impl_judege_connection(input: TokenStream) -> TokenStream {
36    let ast = parse_macro_input!(input as DeriveInput);
37    crate::derives::impl_judge_connection_traits(&ast).into()
38}