What changed, and why it matters
This commit is a simple rename of internal functions from 'flush_to_writer' and 'flush_to_vec' to 'drain_to_writer' and 'drain_to_vec'. The word 'flush' was confusing because it normally means something specific in I/O code, so the team chose 'drain' instead. No behavior changed, and there is no security issue.
No action needed. Treat as a normal API naming cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
A pure identifier rename across six files. The functions encode data from an Encoder into a writer or vector; the implementation is unchanged. Call sites, re-exports, documentation, and mutation-test exclusions are updated to match the new names. No functional or security-relevant change is present.
Changed components
consensus_encoding/src/encode/mod.rsconsensus_encoding/src/lib.rsio/src/lib.rsbitcoin/src/crypto/sighash.rsp2p/src/message.rs.cargo/mutants.tomlInspect captured patch +18 / −18
diff --git a/.cargo/mutants.toml b/.cargo/mutants.toml
index ef425ab7..d6f5d5f2 100644
--- a/.cargo/mutants.toml
+++ b/.cargo/mutants.toml
@@ -73,6 +73,6 @@ exclude_re = [
"consensus_encoding/.* decode_from_read", # Mutations cause an infinite loop
"consensus_encoding/.* <impl Decoder for .*>::push_bytes", # Mutations cause an infinite loop
"consensus_encoding/.* <impl Encoder for .*>::advance", # Replacing the return with true causes an infinite loop.
- "consensus_encoding/.* delete ! in flush_to_vec", # Causes an infinite loop.
- "consensus_encoding/.* delete ! in flush_to_writer", # Causes an infinite loop.
+ "consensus_encoding/.* delete ! in drain_to_vec", # Causes an infinite loop.
+ "consensus_encoding/.* delete ! in drain_to_writer", # Causes an infinite loop.
]
diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs
index 709ac712..0fac99c7 100644
--- a/bitcoin/src/crypto/sighash.rs
+++ b/bitcoin/src/crypto/sighash.rs
@@ -392,7 +392,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
encoding::CompactSizeEncoder::new(annex.0.len()),
encoding::BytesEncoder::without_length_prefix(annex.0),
);
- io::flush_to_writer(&mut encoder, &mut enc)?;
+ io::drain_to_writer(&mut encoder, &mut enc)?;
let hash = sha256::Hash::from_engine(enc);
writer.write_all(&hash.to_byte_array())?;
}
@@ -704,7 +704,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
encoding::CompactSizeEncoder::new(self_.outputs.len()),
encoding::SliceEncoder::without_length_prefix(&self_.outputs),
);
- io::flush_to_writer(&mut encoder, &mut writer)?;
+ io::drain_to_writer(&mut encoder, &mut writer)?;
}
EcdsaSighashType::Single => {
// sign all outputs up to and including this one, but erase
diff --git a/consensus_encoding/src/encode/mod.rs b/consensus_encoding/src/encode/mod.rs
index f80ea15b..12ba504c 100644
--- a/consensus_encoding/src/encode/mod.rs
+++ b/consensus_encoding/src/encode/mod.rs
@@ -283,12 +283,12 @@ where
T: Encodable + ?Sized,
{
let mut encoder = object.encoder();
- flush_to_vec(&mut encoder)
+ drain_to_vec(&mut encoder)
}
-/// Flushes the output of an [`Encoder`] into a vector.
+/// Drains the output of an [`Encoder`] into a vector.
#[cfg(feature = "alloc")]
-pub fn flush_to_vec<T>(encoder: &mut T) -> Vec<u8>
+pub fn drain_to_vec<T>(encoder: &mut T) -> Vec<u8>
where
T: Encoder + ?Sized,
{
@@ -320,10 +320,10 @@ where
W: std::io::Write,
{
let mut encoder = object.encoder();
- flush_to_writer(&mut encoder, writer)
+ drain_to_writer(&mut encoder, writer)
}
-/// Flushes the output of an [`Encoder`] to a standard I/O writer.
+/// Drains the output of an [`Encoder`] to a standard I/O writer.
///
/// See [`encode_to_writer`] for more information.
///
@@ -331,7 +331,7 @@ where
///
/// Returns any I/O error encountered while writing to the writer.
#[cfg(feature = "std")]
-pub fn flush_to_writer<T, W>(encoder: &mut T, mut writer: W) -> Result<(), std::io::Error>
+pub fn drain_to_writer<T, W>(encoder: &mut T, mut writer: W) -> Result<(), std::io::Error>
where
T: Encoder + ?Sized,
W: std::io::Write,
diff --git a/consensus_encoding/src/lib.rs b/consensus_encoding/src/lib.rs
index 2e2361a4..a084d335 100644
--- a/consensus_encoding/src/lib.rs
+++ b/consensus_encoding/src/lib.rs
@@ -44,9 +44,9 @@
//! And on the encoding side we provide:
//!
//! * [`encode_to_writer`]: Encode to a stdlib writer.
-//! * [`flush_to_writer`]: Flush an encoder to a stdlib writer.
+//! * [`drain_to_writer`]: Drain an encoder to a stdlib writer.
//! * [`encode_to_vec`]: Encode to the heap.
-//! * [`flush_to_vec`]: Flush an encoder to the heap.
+//! * [`drain_to_vec`]: Drain an encoder to the heap.
//!
//! # Feature Flags
//!
@@ -91,10 +91,10 @@ pub use self::encode::encoders::{
};
#[cfg(feature = "alloc")]
#[doc(inline)]
-pub use self::encode::{encode_to_vec, flush_to_vec};
+pub use self::encode::{encode_to_vec, drain_to_vec};
#[cfg(feature = "std")]
#[doc(inline)]
-pub use self::encode::{encode_to_writer, flush_to_writer};
+pub use self::encode::{encode_to_writer, drain_to_writer};
#[doc(inline)]
pub use self::encode::{Encodable, Encoder, EncoderByteIter, ExactSizeEncoder};
#[cfg(feature = "alloc")]
diff --git a/io/src/lib.rs b/io/src/lib.rs
index 16759340..30599c10 100644
--- a/io/src/lib.rs
+++ b/io/src/lib.rs
@@ -464,17 +464,17 @@ where
W: Write,
{
let mut encoder = object.encoder();
- flush_to_writer(&mut encoder, writer)
+ drain_to_writer(&mut encoder, writer)
}
-/// Flushes the output of an [`Encoder`] to an I/O writer.
+/// Drains 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<()>
+pub fn drain_to_writer<T, W>(encoder: &mut T, mut writer: W) -> Result<()>
where
T: Encoder + ?Sized,
W: Write,
diff --git a/p2p/src/message.rs b/p2p/src/message.rs
index dcd0a086..41034bfa 100644
--- a/p2p/src/message.rs
+++ b/p2p/src/message.rs
@@ -3244,7 +3244,7 @@ mod test {
let mut encoder = cmd.encoder();
assert_eq!(encoder.len(), expected_bytes.len());
- let encoded = encoding::flush_to_vec(&mut encoder);
+ let encoded = encoding::drain_to_vec(&mut encoder);
assert_eq!(encoded, expected_bytes);
}
}
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.