Skip to content

Commit 262d13c

Browse files
committed
Rename Bufferfish::clear to Bufferfish::reset
1 parent d8343dd commit 262d13c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

rust/bufferfish-core/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl Bufferfish {
152152
}
153153

154154
/// Clears the buffer and resets the cursor to the start position.
155-
pub fn clear(&mut self) {
155+
pub fn reset(&mut self) {
156156
self.inner.get_mut().clear();
157157
self.inner.set_position(0);
158158
self.reading = false;
@@ -161,7 +161,7 @@ impl Bufferfish {
161161
/// Resizes the internal buffer to the given size (in bytes).
162162
/// This resets the buffer state and clears any existing data.
163163
pub fn truncate(&mut self, len: usize) {
164-
self.clear();
164+
self.reset();
165165
self.inner.get_mut().truncate(len);
166166
self.inner.set_position(0);
167167
self.reading = false;

rust/bufferfish/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,4 +1011,16 @@ mod tests {
10111011
assert!(result_should_err.is_err());
10121012
assert!(result_should_ok.is_ok());
10131013
}
1014+
1015+
#[test]
1016+
fn test_reset() {
1017+
let mut bf = Bufferfish::new();
1018+
bf.write_u8(0).unwrap();
1019+
bf.write_u8(255).unwrap();
1020+
1021+
bf.reset();
1022+
1023+
assert_eq!(bf.len(), 0);
1024+
assert_eq!(bf.as_ref(), &[]);
1025+
}
10141026
}

typescript/src/bufferfish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class Bufferfish {
100100
/**
101101
* Clears the buffer and resets the cursor to the start position.
102102
*/
103-
public clear = (): void => {
103+
public reset = (): void => {
104104
this.inner = new Uint8Array(0)
105105
this.position = 0
106106
this.reading = false
@@ -111,7 +111,7 @@ export class Bufferfish {
111111
* This resets the buffer state and clears any existing data.
112112
*/
113113
public truncate = (length: number): void => {
114-
this.clear()
114+
this.reset()
115115
this.inner = this.inner.subarray(0, length)
116116
this.position = 0
117117
this.max_capacity = length

0 commit comments

Comments
 (0)