@@ -10,12 +10,12 @@ use futures_lite::AsyncReadExt;
1010pub use super :: sidebands:: WithSidebands ;
1111use crate :: {
1212 decode,
13- read:: { ExhaustiveOutcome , ProgressAction } ,
14- PacketLineRef , StreamingPeekableIterState , MAX_LINE_LEN , U16_HEX_BYTES ,
13+ read:: { ExhaustiveOutcome , ProgressAction , StreamingPeekableIterState } ,
14+ PacketLineRef , MAX_LINE_LEN , U16_HEX_BYTES ,
1515} ;
1616
1717/// Read pack lines one after another, without consuming more than needed from the underlying
18- /// [`AsyncRead`]. [`Flush`][ PacketLineRef::Flush] lines cause the reader to stop producing lines forever,
18+ /// [`AsyncRead`]. [`Flush`]( PacketLineRef::Flush) lines cause the reader to stop producing lines forever,
1919/// leaving [`AsyncRead`] at the start of whatever comes next.
2020///
2121/// This implementation tries hard not to allocate at all which leads to quite some added complexity and plenty of extra memory copies.
3636 }
3737 }
3838
39- #[ allow( clippy:: needless_lifetimes) ] // TODO: remove once this is clippy false positive is fixed
4039 async fn read_line_inner < ' a > (
4140 reader : & mut T ,
4241 buf : & ' a mut [ u8 ] ,
@@ -127,33 +126,32 @@ where
127126 /// Returns `None` if the end of iteration is reached because of one of the following:
128127 ///
129128 /// * natural EOF
130- /// * ERR packet line encountered if [`fail_on_err_lines()`][StreamingPeekableIter ::fail_on_err_lines()] is true.
129+ /// * ERR packet line encountered if [`fail_on_err_lines()`](StreamingPeekableIterState ::fail_on_err_lines()) is true.
131130 /// * A `delimiter` packet line encountered
132131 pub async fn read_line ( & mut self ) -> Option < io:: Result < Result < PacketLineRef < ' _ > , decode:: Error > > > {
133- if self . state . is_done {
132+ let state = & mut self . state ;
133+ if state. is_done {
134134 return None ;
135135 }
136- if !self . state . peek_buf . is_empty ( ) {
137- std:: mem:: swap ( & mut self . state . peek_buf , & mut self . state . buf ) ;
138- self . state . peek_buf . clear ( ) ;
139- Some ( Ok ( Ok (
140- crate :: decode ( & self . state . buf ) . expect ( "only valid data in peek buf" )
141- ) ) )
136+ if !state. peek_buf . is_empty ( ) {
137+ std:: mem:: swap ( & mut state. peek_buf , & mut state. buf ) ;
138+ state. peek_buf . clear ( ) ;
139+ Some ( Ok ( Ok ( crate :: decode ( & state. buf ) . expect ( "only valid data in peek buf" ) ) ) )
142140 } else {
143- if self . state . buf . len ( ) != MAX_LINE_LEN {
144- self . state . buf . resize ( MAX_LINE_LEN , 0 ) ;
141+ if state. buf . len ( ) != MAX_LINE_LEN {
142+ state. buf . resize ( MAX_LINE_LEN , 0 ) ;
145143 }
146144 let ( is_done, stopped_at, res) = Self :: read_line_inner_exhaustive (
147- & mut self . state . read ,
148- & mut self . state . buf ,
149- self . state . delimiters ,
150- self . state . fail_on_err_lines ,
145+ & mut state. read ,
146+ & mut state. buf ,
147+ state. delimiters ,
148+ state. fail_on_err_lines ,
151149 false ,
152- self . state . trace ,
150+ state. trace ,
153151 )
154152 . await ;
155- self . state . is_done = is_done;
156- self . state . stopped_at = stopped_at;
153+ state. is_done = is_done;
154+ state. stopped_at = stopped_at;
157155 res
158156 }
159157 }
@@ -163,56 +161,55 @@ where
163161 ///
164162 /// Multiple calls to peek will return the same packet line, if there is one.
165163 pub async fn peek_line ( & mut self ) -> Option < io:: Result < Result < PacketLineRef < ' _ > , decode:: Error > > > {
166- if self . state . is_done {
164+ let state = & mut self . state ;
165+ if state. is_done {
167166 return None ;
168167 }
169- if self . state . peek_buf . is_empty ( ) {
170- self . state . peek_buf . resize ( MAX_LINE_LEN , 0 ) ;
168+ if state. peek_buf . is_empty ( ) {
169+ state. peek_buf . resize ( MAX_LINE_LEN , 0 ) ;
171170 let ( is_done, stopped_at, res) = Self :: read_line_inner_exhaustive (
172- & mut self . state . read ,
173- & mut self . state . peek_buf ,
174- self . state . delimiters ,
175- self . state . fail_on_err_lines ,
171+ & mut state. read ,
172+ & mut state. peek_buf ,
173+ state. delimiters ,
174+ state. fail_on_err_lines ,
176175 true ,
177- self . state . trace ,
176+ state. trace ,
178177 )
179178 . await ;
180- self . state . is_done = is_done;
181- self . state . stopped_at = stopped_at;
179+ state. is_done = is_done;
180+ state. stopped_at = stopped_at;
182181 res
183182 } else {
184- Some ( Ok ( Ok (
185- crate :: decode ( & self . state . peek_buf ) . expect ( "only valid data here" )
186- ) ) )
183+ Some ( Ok ( Ok ( crate :: decode ( & state. peek_buf ) . expect ( "only valid data here" ) ) ) )
187184 }
188185 }
189186
190- /// Same as [`as_read_with_sidebands(…)`][ StreamingPeekableIter::as_read_with_sidebands()] , but for channels without side band support.
187+ /// Same as [`as_read_with_sidebands(…)`]( StreamingPeekableIter::as_read_with_sidebands()) , but for channels without side band support.
191188 ///
192189 /// Due to the preconfigured function type this method can be called without 'turbofish'.
193190 #[ allow( clippy:: type_complexity) ]
194191 pub fn as_read ( & mut self ) -> WithSidebands < ' _ , T , fn ( bool , & [ u8 ] ) -> ProgressAction > {
195192 WithSidebands :: new ( self )
196193 }
197194
198- /// Return this instance as implementor of [`Read`][ io::Read] assuming side bands to be used in all received packet lines.
199- /// Each invocation of [`read_line()`][ io::BufRead::read_line()] returns a packet line.
195+ /// Return this instance as implementor of [`Read`]( io::Read) assuming sidebands to be used in all received packet lines.
196+ /// Each invocation of [`read_line()`]( io::BufRead::read_line()) returns a packet line.
200197 ///
201198 /// Progress or error information will be passed to the given `handle_progress(is_error, text)` function, with `is_error: bool`
202199 /// being true in case the `text` is to be interpreted as error.
203200 ///
204- /// _Please note_ that side bands need to be negotiated with the server.
201+ /// _Please note_ that sidebands need to be negotiated with the server.
205202 pub fn as_read_with_sidebands < F : FnMut ( bool , & [ u8 ] ) -> ProgressAction + Unpin > (
206203 & mut self ,
207204 handle_progress : F ,
208205 ) -> WithSidebands < ' _ , T , F > {
209206 WithSidebands :: with_progress_handler ( self , handle_progress)
210207 }
211208
212- /// Same as [`as_read_with_sidebands(…)`][ StreamingPeekableIter::as_read_with_sidebands()] , but for channels without side band support.
209+ /// Same as [`as_read_with_sidebands(…)`]( StreamingPeekableIter::as_read_with_sidebands()) , but for channels without side band support.
213210 ///
214211 /// The type parameter `F` needs to be configured for this method to be callable using the 'turbofish' operator.
215- /// Use [`as_read()`][ StreamingPeekableIter::as_read()] .
212+ /// Use [`as_read()`]( StreamingPeekableIter::as_read()) .
216213 pub fn as_read_without_sidebands < F : FnMut ( bool , & [ u8 ] ) -> ProgressAction + Unpin > (
217214 & mut self ,
218215 ) -> WithSidebands < ' _ , T , F > {
0 commit comments