@@ -14,14 +14,13 @@ pin_project! {
1414 pub struct Take <R > {
1515 #[ pin]
1616 inner: R ,
17- // Add '_' to avoid conflicts with `limit` method.
18- limit_: u64 ,
17+ limit: u64 ,
1918 }
2019}
2120
2221impl < R : AsyncRead > Take < R > {
2322 pub ( super ) fn new ( inner : R , limit : u64 ) -> Self {
24- Self { inner, limit_ : limit }
23+ Self { inner, limit }
2524 }
2625
2726 /// Returns the remaining number of bytes that can be
@@ -48,7 +47,7 @@ impl<R: AsyncRead> Take<R> {
4847 /// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
4948 /// ```
5049 pub fn limit ( & self ) -> u64 {
51- self . limit_
50+ self . limit
5251 }
5352
5453 /// Sets the number of bytes that can be read before this instance will
@@ -78,7 +77,7 @@ impl<R: AsyncRead> Take<R> {
7877 /// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
7978 /// ```
8079 pub fn set_limit ( & mut self , limit : u64 ) {
81- self . limit_ = limit
80+ self . limit = limit
8281 }
8382
8483 delegate_access_inner ! ( inner, R , ( ) ) ;
@@ -92,13 +91,13 @@ impl<R: AsyncRead> AsyncRead for Take<R> {
9291 ) -> Poll < Result < usize , io:: Error > > {
9392 let this = self . project ( ) ;
9493
95- if * this. limit_ == 0 {
94+ if * this. limit == 0 {
9695 return Poll :: Ready ( Ok ( 0 ) ) ;
9796 }
9897
99- let max = cmp:: min ( buf. len ( ) as u64 , * this. limit_ ) as usize ;
98+ let max = cmp:: min ( buf. len ( ) as u64 , * this. limit ) as usize ;
10099 let n = ready ! ( this. inner. poll_read( cx, & mut buf[ ..max] ) ) ?;
101- * this. limit_ -= n as u64 ;
100+ * this. limit -= n as u64 ;
102101 Poll :: Ready ( Ok ( n) )
103102 }
104103
@@ -113,21 +112,21 @@ impl<R: AsyncBufRead> AsyncBufRead for Take<R> {
113112 let this = self . project ( ) ;
114113
115114 // Don't call into inner reader at all at EOF because it may still block
116- if * this. limit_ == 0 {
115+ if * this. limit == 0 {
117116 return Poll :: Ready ( Ok ( & [ ] ) ) ;
118117 }
119118
120119 let buf = ready ! ( this. inner. poll_fill_buf( cx) ?) ;
121- let cap = cmp:: min ( buf. len ( ) as u64 , * this. limit_ ) as usize ;
120+ let cap = cmp:: min ( buf. len ( ) as u64 , * this. limit ) as usize ;
122121 Poll :: Ready ( Ok ( & buf[ ..cap] ) )
123122 }
124123
125124 fn consume ( self : Pin < & mut Self > , amt : usize ) {
126125 let this = self . project ( ) ;
127126
128127 // Don't let callers reset the limit by passing an overlarge value
129- let amt = cmp:: min ( amt as u64 , * this. limit_ ) as usize ;
130- * this. limit_ -= amt as u64 ;
128+ let amt = cmp:: min ( amt as u64 , * this. limit ) as usize ;
129+ * this. limit -= amt as u64 ;
131130 this. inner . consume ( amt) ;
132131 }
133132}
0 commit comments