cdrs_helpers_derive_temp/
lib.rs

1//! This trait provides functionality for derivation  `IntoCDRSBytes` trait implementation
2//! for underlying
3
4extern crate proc_macro;
5#[macro_use]
6extern crate quote;
7extern crate rand;
8extern crate syn;
9
10mod common;
11mod into_cdrs_value;
12mod try_from_row;
13mod try_from_udt;
14
15use proc_macro::TokenStream;
16use into_cdrs_value::impl_into_cdrs_value;
17use try_from_row::impl_try_from_row;
18use try_from_udt::impl_try_from_udt;
19
20#[proc_macro_derive(IntoCDRSValue)]
21pub fn into_cdrs_value(input: TokenStream) -> TokenStream {
22    // Construct a string representation of the type definition
23    let s = input.to_string();
24
25    // Parse the string representation
26    let ast = syn::parse_derive_input(&s).unwrap();
27
28    // Build the impl
29    let gen = impl_into_cdrs_value(&ast);
30
31    // Return the generated impl
32    gen.parse().unwrap()
33}
34
35#[proc_macro_derive(TryFromRow)]
36pub fn try_from_row(input: TokenStream) -> TokenStream {
37    // Construct a string representation of the type definition
38    let s = input.to_string();
39
40    // Parse the string representation
41    let ast = syn::parse_derive_input(&s).unwrap();
42
43    // Build the impl
44    let gen = impl_try_from_row(&ast);
45
46    // Return the generated impl
47    gen.parse().unwrap()
48}
49
50#[proc_macro_derive(TryFromUDT)]
51pub fn try_from_udt(input: TokenStream) -> TokenStream {
52    // Construct a string representation of the type definition
53    let s = input.to_string();
54
55    // Parse the string representation
56    let ast = syn::parse_derive_input(&s).unwrap();
57
58    // Build the impl
59    let gen = impl_try_from_udt(&ast);
60
61    // Return the generated impl
62    gen.parse().unwrap()
63}