Attribute Macro scylla_udf::export_newtype

source ·
#[export_newtype]
Expand description

This macro allows (de)serializing a cql type to/from a Rust “newtype” struct.

The macro takes a “newtype” struct (tuple struct with only one field) and generates all implementations for (de)serialization traits used in the scylla_udf macros by treating the struct as the inner type itself.

This allows overriding the impls for the inner type, while still being able to use it in the types of parameters or return values of scylla_udf functions.

For example, for a function using a newtype struct:

#[scylla_udf::export_newtype]
struct MyInt(i32);

#[scylla_udf::export_udf]
fn foo(arg: MyInt) -> MyInt {
    ...
}

and a table:

CREATE TABLE table (x int PRIMARY KEY);

you can use the function in a query:

SELECT foo(x) FROM table;