@@ -14,14 +14,13 @@ pin_project! {
14
14
pub struct Take <R > {
15
15
#[ pin]
16
16
inner: R ,
17
- // Add '_' to avoid conflicts with `limit` method.
18
- limit_: u64 ,
17
+ limit: u64 ,
19
18
}
20
19
}
21
20
22
21
impl < R : AsyncRead > Take < R > {
23
22
pub ( super ) fn new ( inner : R , limit : u64 ) -> Self {
24
- Self { inner, limit_ : limit }
23
+ Self { inner, limit }
25
24
}
26
25
27
26
/// Returns the remaining number of bytes that can be
@@ -48,7 +47,7 @@ impl<R: AsyncRead> Take<R> {
48
47
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
49
48
/// ```
50
49
pub fn limit ( & self ) -> u64 {
51
- self . limit_
50
+ self . limit
52
51
}
53
52
54
53
/// Sets the number of bytes that can be read before this instance will
@@ -78,7 +77,7 @@ impl<R: AsyncRead> Take<R> {
78
77
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
79
78
/// ```
80
79
pub fn set_limit ( & mut self , limit : u64 ) {
81
- self . limit_ = limit
80
+ self . limit = limit
82
81
}
83
82
84
83
delegate_access_inner ! ( inner, R , ( ) ) ;
@@ -92,13 +91,13 @@ impl<R: AsyncRead> AsyncRead for Take<R> {
92
91
) -> Poll < Result < usize , io:: Error > > {
93
92
let this = self . project ( ) ;
94
93
95
- if * this. limit_ == 0 {
94
+ if * this. limit == 0 {
96
95
return Poll :: Ready ( Ok ( 0 ) ) ;
97
96
}
98
97
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 ;
100
99
let n = ready ! ( this. inner. poll_read( cx, & mut buf[ ..max] ) ) ?;
101
- * this. limit_ -= n as u64 ;
100
+ * this. limit -= n as u64 ;
102
101
Poll :: Ready ( Ok ( n) )
103
102
}
104
103
@@ -113,21 +112,21 @@ impl<R: AsyncBufRead> AsyncBufRead for Take<R> {
113
112
let this = self . project ( ) ;
114
113
115
114
// 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 {
117
116
return Poll :: Ready ( Ok ( & [ ] ) ) ;
118
117
}
119
118
120
119
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 ;
122
121
Poll :: Ready ( Ok ( & buf[ ..cap] ) )
123
122
}
124
123
125
124
fn consume ( self : Pin < & mut Self > , amt : usize ) {
126
125
let this = self . project ( ) ;
127
126
128
127
// 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 ;
131
130
this. inner . consume ( amt) ;
132
131
}
133
132
}
0 commit comments