Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify evaluate_function codes by adding macros #349

Closed
panarch opened this issue Sep 14, 2021 · 1 comment
Closed

Simplify evaluate_function codes by adding macros #349

panarch opened this issue Sep 14, 2021 · 1 comment
Assignees

Comments

@panarch
Copy link
Member

panarch commented Sep 14, 2021

This issue is to simplify Nullable enum control flow using declarative macro.

async fn evaluate_function<'a, T: 'static + Debug>(
storage: &'a dyn GStore<T>,
context: Option<Rc<FilterContext<'a>>>,
aggregated: Option<Rc<HashMap<&'a Aggregate, Value>>>,
func: &'a Function,
) -> Result<Evaluated<'a>> {
let eval = |expr| {
let context = context.as_ref().map(Rc::clone);
let aggregated = aggregated.as_ref().map(Rc::clone);
evaluate(storage, context, aggregated, expr)
};
enum Nullable<T> {
Value(T),
Null,
}

When Nullable::Null comes, it always returns Ok(Evaluated::from(Value::Null)).
However, that result is also kind of success Ok. It cannot be handled by try operator ?.
It would be good to use macro until rfcs/3058-try-trait-v2.html comes to Rust stable.

e.g.

Function::Lower(expr) => match eval_to_str(expr).await? {
Nullable::Value(v) => Ok(Value::Str(v.to_lowercase())),
Nullable::Null => Ok(Value::Null),
}
.map(Evaluated::from),

We can change the above like this,

Function::Lower(expr) => {
    let v = eval_to_str!(expr).to_lowercase();

    Ok(Evaluated::from(Value::Str(v)))
}

It is expected for us not to handle Nullable enum explicitly.

@vbbono
Copy link
Contributor

vbbono commented Sep 14, 2021

Thanks! Assign to me :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants