It'd be nice if plugins were available from rust not just python. I think the simplest way would be to have the polars_expr macro also emit a pub fn version of the function. It'd fall short if there were kwarg structs that aren't also public but that's a lot easier for plugin authors to patch for interoperability. ChatGPT suggested this but I don't know enough about macros to tell if it's good enough to put in a PR or even if that's really all it would take.
#[proc_macro_attribute]
pub fn polars_expr(attr: TokenStream, input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as syn::ItemFn);
let fn_name = &ast.sig.ident;
let options = parse_macro_input!(attr as attr::ExprsFunctionOptions);
let expanded_field_fn = if let Some(fn_name) = options.output_type_fn {
create_field_function(fn_name, &fn_name, false)
} else if let Some(fn_name) = options.output_type_fn_kwargs {
create_field_function(fn_name, &fn_name, true)
} else if let Some(dtype) = options.output_dtype {
create_field_function_from_with_dtype(fn_name, dtype)
} else {
panic!("didn't understand polars_expr attribute")
};
let expanded_expr = create_expression_function(&ast);
// Modify the function to ensure it's public
let mut modified_ast = ast.clone();
modified_ast.vis = syn::Visibility::Public(syn::token::Pub { span: proc_macro2::Span::call_site() });
let expanded = quote! {
#expanded_field_fn
#expanded_expr
// Keep the original function as `pub fn`
#modified_ast
};
TokenStream::from(expanded)
}