You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/07/20 19:04:03 UTC

[GitHub] [arrow] jorgecarleitao commented on pull request #7809: ARROW-9534: [Rust] [DataFusion] Add functions to create literal expressions

jorgecarleitao commented on pull request #7809:
URL: https://github.com/apache/arrow/pull/7809#issuecomment-661276604


   Nice! I just needed this in my ballista's PR!
   
   following [this SO answer](https://stackoverflow.com/a/40776087/931303), 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.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org