apache / avro-rs

Rust SDK for Apache Avro - a data serialization system.
https://avro.apache.org/
Apache License 2.0
25 stars 10 forks source link

Support writer owns the schema #56

Open ZENOTME opened 5 days ago

ZENOTME commented 5 days ago

Currently, the writer needs to take a lifetime param and this will make it hard to include in struct sometimes. E.g.

struct OutWriter<'a> {
  avro_schema: avro::Schema
  inner_writer: avro::Writer<'a,Vec<u8>>
}

Even though OutWriter owns the avro_schema, it still needs to define the lifetime param explicitly. And this lifetime will continue to propagate to other types. Self-reference seems a complicated problem https://users.rust-lang.org/t/how-can-we-teach-people-about-self-referential-types/65362/2. So could we just provide a writer who owns the schema and avoids the lifetime param?🤔

martin-g commented 4 days ago

Do you need to keep the inner_writer as a field ? You can create an instance when you need to write something and then discard it, e.g. in OutWriter::write() method.