-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 'Fix scalar API in extensions, add documentation and error hand…
…ling' from Preston Thorpe 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
- Loading branch information
Showing
11 changed files
with
706 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.