ashtuchkin commented on issue #6326:
URL: https://github.com/apache/arrow-rs/issues/6326#issuecomment-2318037042

   That works in simple cases, yes. I've tried this in my slightly more complex 
code and then spent unreasonable amount of time trying to make it work. 
Specifically, the writer in my case is stateful, so I created a struct with 
generic `W: RecordBatchWriter` and needed to specialize it for every format 
manually, like this
   
   ```rust
   struct MyWriter<W: RecordBatchWriter> {
       writer: W,
       ...
   }
   
   let writer: Box<dyn MyWriter> = match args.format {
       "parquet" => 
Box::new(MyWriter::new(parquet::arrow::ArrowWriter::try_new(file, schema, 
None), ...)?),
       ...
   }
   
   use_my_writer_as_part_of_a_pipeline(writer);
   ```
   
   Now we can't really do that ^^ because MyWriter is not a trait, so we need 
to introduce another higher-level trait.
   
   Here's alternative proposal - can we add a `finish(&mut self)` to the trait 
to enable dynamic dispatch? We have a [similar semantics in 
parquet](https://docs.rs/parquet/52.2.0/parquet/arrow/arrow_writer/struct.ArrowWriter.html#method.finish)
 where we have consuming close and non-consuming finish. That should be 
backwards compatible and would resolve the difficulties.


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