What changed, and why it matters
This commit adds a new helper function that lets developers flush an existing data encoder directly to an output writer. It is a straightforward code refactor that splits an existing function into two pieces; there is no indication of a security bug or fix.
No security action required. Treat as a normal API addition / refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces flush_to_writer<T: Encoder + ?Sized, W: Write>(encoder: &mut T, writer: W) -> Result<()>, which contains the loop previously inside encode_to_writer. encode_to_writer is updated to create an encoder and delegate to the new function. The logic is identical: write current_chunk(), call advance(), repeat until finished. No unsafe code, no cryptographic operations, no input validation changes, and no behavioral differences are visible.
Changed components
io/src/lib.rsencode_to_writerflush_to_writerInspect captured patch +16 / −1
diff --git a/io/src/lib.rs b/io/src/lib.rs
index 57d3149f..86d8526c 100644
--- a/io/src/lib.rs
+++ b/io/src/lib.rs
@@ -449,12 +449,27 @@ pub fn from_std_mut<T>(std_io: &mut T) -> &mut FromStd<T> { FromStd::new_mut(std
/// # Errors
///
/// If an I/O error occurs while writing to the underlying writer.
-pub fn encode_to_writer<T, W>(object: &T, mut writer: W) -> Result<()>
+pub fn encode_to_writer<T, W>(object: &T, writer: W) -> Result<()>
where
T: encoding::Encodable + ?Sized,
W: Write,
{
let mut encoder = object.encoder();
+ flush_to_writer(&mut encoder, writer)
+}
+
+/// Flushes the output of an [`Encoder`] to an I/O writer.
+///
+/// See [`encode_to_writer`] for more information.
+///
+/// # Errors
+///
+/// Returns any I/O error encountered while writing to the writer.
+pub fn flush_to_writer<T, W>(encoder: &mut T, mut writer: W) -> Result<()>
+where
+ T: Encoder + ?Sized,
+ W: Write,
+{
loop {
writer.write_all(encoder.current_chunk())?;
if !encoder.advance() {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.