Skip to content

Conversation

@andygrove
Copy link
Member

No description provided.

@github-actions
Copy link

@andygrove andygrove requested review from nevi-me and paddyhoran July 20, 2020 18:39
@andygrove
Copy link
Member Author

@jorgecarleitao fyi

@jorgecarleitao
Copy link
Member

Nice! I just needed this in my ballista's PR!

following this SO answer, what do you think of

trait Literal {
    fn lit(&self) -> ScalarValue;
}

impl Literal for i32 {
    fn lit(&self) -> ScalarValue {
        ScalarValue::Int(self.clone())
    }
}
impl Literal for bool {
    fn lit(&self) -> ScalarValue {
        ScalarValue::Boolean(self.clone())
    }
}

fn lit<T: Literal>(n: T) -> ScalarValue {
    n.lit()
}

# usage:
# lit(2);
# lit(true);

this way, the user does not have to import nor remember the value's type; they can just call lit. It seems to be a common pattern in rust.

@andygrove
Copy link
Member Author

@jorgecarleitao Oh, that is much nicer. Do you want to PR that and I'll close this one?

@jorgecarleitao
Copy link
Member

I can take it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants