Repository navigation
fix: flush Writer on drop - #199
Conversation
|
I will have to do some research before merging this PR. |
|
Understandable, if you have any questions just ask. The implementation is based on |
There was a problem hiding this comment.
Pull Request Overview
This PR ensures the Writer flushes its buffer on drop (like BufWriter) and provides an into_inner method to extract the underlying writer without double-flushing.
- Added a
Dropimpl to auto-flush (errors ignored) whenWriteris dropped. - Implemented
into_innerusingManuallyDropto safely return the inner writer. - Updated tests to call
into_innerafterflushto avoid relying on drop timing.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| avro/tests/union_schema.rs | Added let _ = writer.into_inner()?; to finalize the writer in the test. |
| avro/tests/to_from_avro_datum_schemata.rs | Inserted let _ = writer.into_inner()?; after flush() to match new behavior. |
| avro/src/writer.rs | Expanded into_inner to use ManuallyDrop, added a Drop impl, and updated docs. |
I do not see similar code in LineWriter |
That's because LineWriter is just a wrapper around BufWriter and thus doesn't have to implement this. |
|
Not sure why the CI is angry, I don't see a double get_ref or get_mut implementation. And I can't reproduce it in codespaces |
This brings the writer in line with standard library types like `BufWriter` and `LineWriter`. This is a breaking change when the inner writer is `&mut W` and used later in the scope without dropping the writer or calling `into_inner` (as seen in the fixed tests).
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
6e113ce to
d58ce4d
Compare
|
Thank you once again, @Kriskras99 ! |
|
Thanks for taking the time to do an in-depth review! |
This brings the writer in line with standard library types like
BufWriterandLineWriter.This is a breaking change when the inner writer is
&mut Wand used later in the scope without dropping the writer or callinginto_inner(as seen in the fixed tests).