iron-functions-derive 0.9.0

Part of the Rust SDK for the Iron Functions project.
Documentation
use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput, Data, Error};

/// `flink_input` indicates that a struct is used as an input for a Flink UDF.
/// 
/// This is a no-op macro that doesn't modify the annotated struct.
///
/// # Example
///
/// ```
/// use iron_functions_sdk::*;
///
/// #[flink_input]
/// struct MyInput {
///     field1: String,
///     field2: i32,
/// }
/// ```
#[proc_macro_attribute]
pub fn flink_input(_attr: TokenStream, item: TokenStream) -> TokenStream {
    let item_clone = item.clone();
    let input = parse_macro_input!(item_clone as DeriveInput);

    // Check if the macro is applied to a struct
    match input.data {
        Data::Struct(_) => {
            // If it's a struct, just return the original item
            // This makes it a no-op macro
            item
        },
        _ => {
            Error::new_spanned(
                proc_macro2::TokenStream::from(item),
                "#[flink_input] can only be used on structs"
            )
            .to_compile_error()
            .into()
        }
    }
}

/// `flink_output` indicates that a struct is used as an output for a Flink UDF.
/// 
/// This is a no-op macro that doesn't modify the annotated struct.
///
/// # Example
///
/// ```
/// use iron_functions_sdk::*;
///
/// #[flink_output]
/// struct MyOutput {
///     field1: String,
///     field2: i32,
/// }
/// ```
#[proc_macro_attribute]
pub fn flink_output(_attr: TokenStream, item: TokenStream) -> TokenStream {
    let item_clone = item.clone();
    let input = parse_macro_input!(item_clone as DeriveInput);

    // Check if the macro is applied to a struct
    match input.data {
        Data::Struct(_) => {
            // If it's a struct, just return the original item
            // This makes it a no-op macro
            item
        },
        _ => {
            Error::new_spanned(
                proc_macro2::TokenStream::from(item),
                "#[flink_output] can only be used on structs"
            )
            .to_compile_error()
            .into()
        }
    }
}

#[proc_macro_derive(FlinkTypes, attributes(flink_type))]
pub fn flink_types_derive(input: TokenStream) -> TokenStream {
    let _input = parse_macro_input!(input as DeriveInput);

    TokenStream::new()
}