iron_functions_derive/lib.rs
1use proc_macro::TokenStream;
2use syn::{parse_macro_input, DeriveInput, Data, Error};
3
4/// `flink_input` indicates that a struct is used as an input for a Flink UDF.
5///
6/// This is a no-op macro that doesn't modify the annotated struct.
7///
8/// # Example
9///
10/// ```
11/// use iron_functions_sdk::*;
12///
13/// #[flink_input]
14/// struct MyInput {
15/// field1: String,
16/// field2: i32,
17/// }
18/// ```
19#[proc_macro_attribute]
20pub fn flink_input(_attr: TokenStream, item: TokenStream) -> TokenStream {
21 let item_clone = item.clone();
22 let input = parse_macro_input!(item_clone as DeriveInput);
23
24 // Check if the macro is applied to a struct
25 match input.data {
26 Data::Struct(_) => {
27 // If it's a struct, just return the original item
28 // This makes it a no-op macro
29 item
30 },
31 _ => {
32 Error::new_spanned(
33 proc_macro2::TokenStream::from(item),
34 "#[flink_input] can only be used on structs"
35 )
36 .to_compile_error()
37 .into()
38 }
39 }
40}
41
42/// `flink_output` indicates that a struct is used as an output for a Flink UDF.
43///
44/// This is a no-op macro that doesn't modify the annotated struct.
45///
46/// # Example
47///
48/// ```
49/// use iron_functions_sdk::*;
50///
51/// #[flink_output]
52/// struct MyOutput {
53/// field1: String,
54/// field2: i32,
55/// }
56/// ```
57#[proc_macro_attribute]
58pub fn flink_output(_attr: TokenStream, item: TokenStream) -> TokenStream {
59 let item_clone = item.clone();
60 let input = parse_macro_input!(item_clone as DeriveInput);
61
62 // Check if the macro is applied to a struct
63 match input.data {
64 Data::Struct(_) => {
65 // If it's a struct, just return the original item
66 // This makes it a no-op macro
67 item
68 },
69 _ => {
70 Error::new_spanned(
71 proc_macro2::TokenStream::from(item),
72 "#[flink_output] can only be used on structs"
73 )
74 .to_compile_error()
75 .into()
76 }
77 }
78}
79
80#[proc_macro_derive(FlinkTypes, attributes(flink_type))]
81pub fn flink_types_derive(input: TokenStream) -> TokenStream {
82 let _input = parse_macro_input!(input as DeriveInput);
83
84 TokenStream::new()
85}