dnsco commented on issue #3644:
URL: https://github.com/apache/arrow-rs/issues/3644#issuecomment-1412906085

   So the builders implement extend but an &mut Builder does not have an 
implementation. I'm bashing my head against the wall trying to figure out how 
to make it work.
   
   here's the new method: 
   ```rust
   pub fn set_val<T, R, V, F>(mut builder: T, value: Option<V>, getter: F) -> 
Result<()>
   where
       T: Extend<Option<R>>,
       V: Deref<Target = Value>,
       F: FnOnce(&V::Target) -> Option<R>,
   {
       let v = value
           .as_deref()
           .map(|v| {
               getter(v).ok_or_else(|| {
                   let msg = format!("Could not cast {} to correct type", v);
                   Error::new(InvalidData, msg)
               })
           })
           .transpose()?;
       builder.extend(vec![v]);
       Ok(())
   }
   ```
   
   called as:
   ```rust
   DataType::Float64 => {
               let b = 
struct_builder.field_builder::<Float64Builder>(i).unwrap();
               set_val(b, value, Value::as_f64)?
   }
   ```
   
   Yielding the error:
   ```
   96 |             set_val(b, value, Value::as_f64)?
      |             ------- ^ the trait `Extend<std::option::Option<_>>` is not 
implemented for `&mut PrimitiveBuilder<Float64Type>`
      |             |
      |             required by a bound introduced by this call
      |
      = help: the trait `Extend<std::option::Option<<P as 
ArrowPrimitiveType>::Native>>` is implemented for `PrimitiveBuilder<P>`
   note: required by a bound in `set_val`
     --> project/src/record_conversion/builder_appending.rs:64:8
      |
   62 | pub fn set_val<T, R, V, F>(mut builder: T, value: Option<V>, getter: F) 
-> Result<()>
      |        ------- required by a bound in this
   63 | where
   64 |     T: Extend<Option<R>>,
      |        ^^^^^^^^^^^^^^^^^ required by this bound in `set_val`
      ```
   
   Am I missing something simple? If I try and reference ```*b``` at the 
callsite I get:
   ```
   error[E0507]: cannot move out of `*b` which is behind a mutable reference
     --> prost-arrow/src/record_conversion/builder_appending.rs:96:21
      |
   96 |             set_val(*b, value, Value::as_f64)?
      |                     ^^ move occurs because `*b` has type 
`PrimitiveBuilder<Float64Type>`, which does not implement the `Copy` trait
      ```
   
   Is there a reason there can't be an implementation of Extend for &mut 
Builders?
   
   Thanks!


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