s2json_derive/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4
5//! The `s2json-derive` Rust crate provides ... TODO
6
7mod json;
8mod mvalue;
9mod prim_value;
10
11use json::generate_to_json;
12use mvalue::generate_to_mvalue;
13use prim_value::generate_to_value_prim;
14use proc_macro::TokenStream;
15
16/// Derives the `MValueCompatible` trait for a struct to convert it to a `MValue`.
17#[proc_macro_derive(MValueCompatible)]
18pub fn mvalue_compatible_derive(input: TokenStream) -> TokenStream {
19    let ast = syn::parse(input).unwrap();
20    generate_to_mvalue(&ast)
21}
22
23/// Derives the `Properties` trait for a struct to convert it to a `Properties`.
24#[proc_macro_derive(Properties)]
25pub fn properties_derive(input: TokenStream) -> TokenStream {
26    let ast = syn::parse(input).unwrap();
27    generate_to_mvalue(&ast)
28}
29
30/// Derives the `MValue` trait for a struct to convert it to a `MValue`.
31#[proc_macro_derive(MValue)]
32pub fn mvalue_derive(input: TokenStream) -> TokenStream {
33    let ast = syn::parse(input).unwrap();
34    generate_to_mvalue(&ast)
35}
36
37/// Derives the `JSONProperties` trait for a struct to convert it to a `JSONProperties`.
38#[proc_macro_derive(JSONProperties)]
39pub fn json_properties_derive(input: TokenStream) -> TokenStream {
40    let ast = syn::parse(input).unwrap();
41    generate_to_json(&ast)
42}
43
44/// Derives the `ValuePrimitive` trait for a struct to convert it to a `ValuePrimitive`.
45#[proc_macro_derive(ValuePrimitive)]
46pub fn primitive_value_derive(input: TokenStream) -> TokenStream {
47    let ast = syn::parse(input).unwrap();
48    generate_to_value_prim(&ast)
49}