Skip to content

Commit f595437

Browse files
authored
feat!: make 'flush' method on encoder consume self (#79)
* makes it harder to misuse the API by calling 'flush' when chaining encoding calls by consuming the encoder when flush is called * flush calls can no longer be retried if they fail
1 parent ad0ccb0 commit f595437

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

benches/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ where
2222
I: IntoIterator<Item = M::Symbol>,
2323
{
2424
let mut bitwriter = BitWriter::endian(Vec::new(), BigEndian);
25-
let mut encoder = Encoder::new(model, &mut bitwriter);
25+
let encoder = Encoder::new(model, &mut bitwriter);
2626

2727
encoder.encode_all(input).unwrap();
2828
bitwriter.byte_align().unwrap();

examples/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ where
2626
I: IntoIterator<Item = M::Symbol>,
2727
{
2828
let mut bitwriter = BitWriter::endian(Vec::new(), BigEndian);
29-
let mut encoder = Encoder::new(model, &mut bitwriter);
29+
let encoder = Encoder::new(model, &mut bitwriter);
3030

3131
encoder.encode_all(input).unwrap();
3232
bitwriter.byte_align().unwrap();

src/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ where
9292
/// This method can fail if the underlying [`BitWrite`] cannot be written
9393
/// to.
9494
pub fn encode_all(
95-
&mut self,
95+
mut self,
9696
symbols: impl IntoIterator<Item = M::Symbol>,
9797
) -> Result<(), Error<M::ValueError>> {
9898
for symbol in symbols {
@@ -138,7 +138,7 @@ where
138138
///
139139
/// This method can fail if the underlying [`BitWrite`] cannot be written
140140
/// to.
141-
pub fn flush(&mut self) -> io::Result<()> {
141+
pub fn flush(self) -> io::Result<()> {
142142
self.state.flush()
143143
}
144144

@@ -236,7 +236,7 @@ where
236236
/// # Errors
237237
///
238238
/// This method can fail if the output cannot be written to
239-
pub fn flush(&mut self) -> io::Result<()> {
239+
pub fn flush(mut self) -> io::Result<()> {
240240
self.pending += 1;
241241
if self.state.low <= self.state.quarter() {
242242
self.emit(false)?;

tests/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ where
1717
M: Model,
1818
{
1919
let mut bitwriter = BitWriter::endian(Vec::new(), BigEndian);
20-
let mut encoder = Encoder::new(model, &mut bitwriter);
20+
let encoder = Encoder::new(model, &mut bitwriter);
2121

2222
encoder.encode_all(input).unwrap();
2323
bitwriter.byte_align().unwrap();

0 commit comments

Comments
 (0)