mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-30 06:24:21 +01:00
Closes #728 Changes the API to one macro/annotation on the relevant function ```rust #[scalar(name = "uuid4_str", alias = "gen_random_uuid")] fn uuid4_str(_args: &[Value]) -> Value { let uuid = uuid::Uuid::new_v4().to_string(); Value::from_text(uuid) } register_extension! { scalars: { uuid4_str, uuid4 } } ``` The only downside of this, is that for functions that use their arguments, because this is not a trait, there is not really a way of enforcing the function signature like there is with the other way. Documentation has been added for this in the `scalar` macro, so hopefully will not be an issue. Also this PR cleans up the Aggregate API by changing the `args` and `name` functions to constant associated types, as well as adds some error handling and documentation. ```rust impl AggFunc for Median { type State = Vec<f64>; const NAME: &'static str = "median"; const ARGS: i32 = 1; fn step(state: &mut Self::State, args: &[Value]) { if let Some(val) = args.first().and_then(Value::to_float) { state.push(val); } } //.. etc ``` Closes #735