File tree Expand file tree Collapse file tree 1 file changed +3
-7
lines changed
src/uucore/src/lib/features Expand file tree Collapse file tree 1 file changed +3
-7
lines changed Original file line number Diff line number Diff line change @@ -43,17 +43,13 @@ use std::collections::VecDeque;
4343pub struct RingBuffer < T > {
4444 /// The data stored in the ring buffer.
4545 pub data : VecDeque < T > ,
46-
47- /// The maximum number of elements that the ring buffer can hold.
48- size : usize ,
4946}
5047
5148impl < T > RingBuffer < T > {
5249 /// Create a new ring buffer with a maximum size of `size`.
5350 pub fn new ( size : usize ) -> Self {
5451 Self {
55- data : VecDeque :: new ( ) ,
56- size,
52+ data : VecDeque :: with_capacity ( size) ,
5753 }
5854 }
5955
@@ -100,10 +96,10 @@ impl<T> RingBuffer<T> {
10096 /// assert_eq!(Some(2), buf.push_back(2));
10197 /// ```
10298 pub fn push_back ( & mut self , value : T ) -> Option < T > {
103- if self . size == 0 {
99+ if self . data . capacity ( ) == 0 {
104100 return Some ( value) ;
105101 }
106- let result = if self . size <= self . data . len ( ) {
102+ let result = if self . data . len ( ) == self . data . capacity ( ) {
107103 self . data . pop_front ( )
108104 } else {
109105 None
You can’t perform that action at this time.
0 commit comments