Skip to content

Commit 79e12df

Browse files
committed
add reset method
1 parent e0995ce commit 79e12df

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

block-buffer/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- `ReadBuffer` type ([#823])
1010
- Optional implementation of the `Zeroize` trait ([#963])
1111
- Generic `serialize` and `deserialize` methods ([#1200])
12-
- `ReadBuffer::{read_cached, write_block}` methods ([#1201])
12+
- `ReadBuffer::{read_cached, write_block, reset}` methods ([#1201])
1313

1414
### Changed
1515
- Block sizes must be bigger than 0 and smaller than 256.

block-buffer/src/read.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ impl<BS: ArraySize> ReadBuffer<BS> {
121121
unsafe { self.set_pos_unchecked(read_len) };
122122
}
123123

124+
/// Reset buffer into exhausted state.
125+
pub fn reset(&mut self) {
126+
self.buffer[0] = BS::U8;
127+
}
128+
124129
/// Write remaining data inside buffer into `buf`, fill remaining space
125130
/// in `buf` with blocks generated by `gen_block`, and save leftover data
126131
/// from the last generated block into the buffer for future use.

block-buffer/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ fn test_read() {
108108
assert_eq!(buf.remaining(), 1);
109109

110110
buf.write_block(0, |_| unreachable!(), |_| unreachable!());
111-
assert_eq!(buf.remaining(), 0);
111+
assert_eq!(buf.remaining(), 1);
112112
let res = buf.read_cached(10);
113-
assert!(res.is_empty());
113+
assert_eq!(res, [7]);
114114

115115
buf.write_block(1, &mut g, |buf| assert_eq!(buf, [8]));
116116
assert_eq!(buf.remaining(), 3);

0 commit comments

Comments
 (0)