alamb commented on issue #655:
URL: https://github.com/apache/arrow-rs/issues/655#issuecomment-899806005


   Hi @arucil  -- this is a tricky one for sure. My Rust Fu this afternoon is 
not quite up to the task
   
   I think I was making progress by defining a marker trait so we could have a 
single `FromIter` implementation
   
   Something like this:
   
   ```rust
   // Define a marker trait so we can implement FromIter for wrapped
   // Options variants as well as non Option variants
   // 
https://stackoverflow.com/questions/39159226/conflicting-implementations-of-trait-in-rust
   trait IntoPrimitiveOption : Sized {
       type Primitive;
   
       // Convert self into an Option
       fn into_primitive_opt(&self) -> Option<Self::Primitive>;
   }
   
   ...
   impl<T: ArrowPrimitiveType, P: IntoPrimitiveOption<Primitive=T>>
       FromIterator<P> for PrimitiveArray<T>
   {
   ...
   }
   
   
   ```
   
   However,  my attempts to define `IntoPrimitiveOption` correctly for 
`ArrowPrimitiveType` was not getting anywhere. Maybe we need to do it for 
individually for each type that implements ArrowPrimitiveType? I am not sure 
though.
   
   This didn't work 
   
   ```rust
   
   impl <T: ArrowPrimitiveType> IntoPrimitiveOption for T{
       type Primitive = T::Native;
   
       fn into_primitive_opt(&self) -> Option<Self::Primitive> {
           let v:T = *self;
           Some(v)
       }
   }
   
   impl <T: ArrowPrimitiveType> IntoPrimitiveOption for Option<T>{
       type Primitive = T::Native;
   
       fn into_primitive_opt(&self) -> Option<Self::Primitive> {
           self.cloned()
       }
   }
   
   ```
   
   FYI @jorgecarleitao 


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to