ion_proc/
lib.rs

1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6
7#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
8
9use proc_macro::TokenStream;
10use quote::ToTokens as _;
11use syn::parse_macro_input;
12
13use crate::class::impl_js_class;
14use crate::function::impl_js_fn;
15use crate::trace::impl_trace;
16use crate::value::{impl_from_value, impl_to_value};
17
18pub(crate) mod attribute;
19pub(crate) mod class;
20pub(crate) mod function;
21mod trace;
22pub(crate) mod utils;
23pub(crate) mod value;
24pub(crate) mod visitors;
25
26#[proc_macro_attribute]
27pub fn js_fn(_attr: TokenStream, stream: TokenStream) -> TokenStream {
28	match impl_js_fn(parse_macro_input!(stream)) {
29		Ok(function) => function.into_token_stream().into(),
30		Err(error) => error.to_compile_error().into(),
31	}
32}
33
34#[proc_macro_attribute]
35pub fn js_class(_attr: TokenStream, stream: TokenStream) -> TokenStream {
36	match impl_js_class(parse_macro_input!(stream)) {
37		Ok(module) => module.into_token_stream().into(),
38		Err(error) => error.to_compile_error().into(),
39	}
40}
41
42#[proc_macro_derive(Traceable, attributes(trace))]
43pub fn trace(input: TokenStream) -> TokenStream {
44	match impl_trace(parse_macro_input!(input)) {
45		Ok(trace) => trace.into_token_stream().into(),
46		Err(error) => error.to_compile_error().into(),
47	}
48}
49
50#[proc_macro_derive(FromValue, attributes(ion))]
51pub fn from_value(input: TokenStream) -> TokenStream {
52	match impl_from_value(parse_macro_input!(input)) {
53		Ok(from_value) => from_value.into_token_stream().into(),
54		Err(error) => error.to_compile_error().into(),
55	}
56}
57
58#[proc_macro_derive(ToValue, attributes(ion))]
59pub fn to_value(input: TokenStream) -> TokenStream {
60	match impl_to_value(parse_macro_input!(input)) {
61		Ok(to_value) => to_value.into_token_stream().into(),
62		Err(error) => error.to_compile_error().into(),
63	}
64}