File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments