Skip to content

#[udf] macro for simple functions #53

Description

@tgross35

It would be nice to provide a simplified interface for the most common needs:

#[udf]
fn my_udf(a: Option<&str>, b: f64, c: &str) -> Option<i32> {
}

#[udf]
fn my_udf2(cache: &mut Vec<u8>, a: Option<&str>, b: f64, c: &str) -> Result<&[u8], String> {
}

// If init is not specified, default to Default
#[udf(init = MyStruct::new())]
fn my_udf3(cache: &mut MyStruct, a: Option<&str>, b: f64, c: &str) -> &[u8] {
}

// desugars to something like
mod my_udf_mod {
    struct MyUdf(Vec<u8>);

    #[register]
    impl BasicUdf for MyUdf {
        returning = Option<i32>;
        fn init(...) { /* autogenerated, verify types */ }
        fn process(&mut self...) {
            // generate user defined types
            let arg1 = args.get(0).as_str();
            my_udf(self.0, arg1, arg2, arg3)
        }
    }
    
    fn my_udf(a: Option<&str>, b: f64, c: &str) -> Option<i32> {
    }
}

The work would be entirely in the proc macro and would just desugar to our current traits. Some way to define >1 function signature would also be cool, but I don't quite know how to combine them together without having them in the same block

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions