Skip to main content

cdrs_tokio_helpers_derive/
lib.rs

1//! This trait provides functionality for derivation  `IntoCDRSBytes` trait implementation
2//! for underlying
3use proc_macro::TokenStream;
4use syn::{parse_macro_input, DeriveInput, Error};
5
6mod common;
7mod db_mirror;
8mod into_cdrs_value;
9mod try_from_row;
10mod try_from_udt;
11
12use crate::db_mirror::impl_db_mirror;
13use crate::into_cdrs_value::impl_into_cdrs_value;
14use crate::try_from_row::impl_try_from_row;
15use crate::try_from_udt::impl_try_from_udt;
16
17#[proc_macro_derive(DbMirror)]
18pub fn db_mirror(input: TokenStream) -> TokenStream {
19    // Parse the string representation
20    let ast = parse_macro_input!(input as DeriveInput);
21
22    // Build the impl
23    impl_db_mirror(&ast)
24        .unwrap_or_else(Error::into_compile_error)
25        .into()
26}
27
28#[proc_macro_derive(IntoCdrsValue)]
29pub fn into_cdrs_value(input: TokenStream) -> TokenStream {
30    // Parse the string representation
31    let ast = parse_macro_input!(input as DeriveInput);
32
33    // Build the impl
34    impl_into_cdrs_value(&ast)
35        .unwrap_or_else(Error::into_compile_error)
36        .into()
37}
38
39#[proc_macro_derive(TryFromRow)]
40pub fn try_from_row(input: TokenStream) -> TokenStream {
41    // Parse the string representation
42    let ast = parse_macro_input!(input as DeriveInput);
43
44    // Build the impl
45    impl_try_from_row(&ast)
46        .unwrap_or_else(Error::into_compile_error)
47        .into()
48}
49
50#[proc_macro_derive(TryFromUdt)]
51pub fn try_from_udt(input: TokenStream) -> TokenStream {
52    // Parse the string representation
53    let ast = parse_macro_input!(input as DeriveInput);
54
55    // Build the impl
56    impl_try_from_udt(&ast)
57        .unwrap_or_else(Error::into_compile_error)
58        .into()
59}