1- use crate :: { codecs:: Encode , core:: util:: PartialBuffer } ;
1+ use crate :: {
2+ codecs:: EncodeV2 ,
3+ core:: util:: { PartialBuffer , WriteBuffer } ,
4+ } ;
25use std:: { io:: Result , ops:: ControlFlow } ;
36
47#[ derive( Debug ) ]
@@ -26,8 +29,8 @@ impl Encoder {
2629 /// `input` - should be `None` if `Poll::Pending`.
2730 pub fn do_poll_read (
2831 & mut self ,
29- output : & mut PartialBuffer < & mut [ u8 ] > ,
30- encoder : & mut impl Encode ,
32+ output : & mut WriteBuffer < ' _ > ,
33+ encoder : & mut dyn EncodeV2 ,
3134 mut input : Option < & mut PartialBuffer < & [ u8 ] > > ,
3235 ) -> ControlFlow < Result < ( ) > > {
3336 loop {
@@ -81,12 +84,12 @@ impl Encoder {
8184 State :: Done => return ControlFlow :: Break ( Ok ( ( ) ) ) ,
8285 } ;
8386
84- if output. unwritten ( ) . is_empty ( ) {
87+ if output. has_no_spare_space ( ) {
8588 return ControlFlow :: Break ( Ok ( ( ) ) ) ;
8689 }
8790 }
8891
89- if output. unwritten ( ) . is_empty ( ) {
92+ if output. has_no_spare_space ( ) {
9093 ControlFlow :: Break ( Ok ( ( ) ) )
9194 } else {
9295 ControlFlow :: Continue ( ( ) )
@@ -113,7 +116,7 @@ macro_rules! impl_encoder {
113116 }
114117 }
115118
116- impl <R : AsyncBufRead , E : Encode > Encoder <R , E > {
119+ impl <R : AsyncBufRead , E : EncodeV2 > Encoder <R , E > {
117120 pub fn new( reader: R , encoder: E ) -> Self {
118121 Self {
119122 reader,
@@ -149,46 +152,52 @@ macro_rules! impl_encoder {
149152 }
150153 }
151154
152- impl <R : AsyncBufRead , E : Encode > Encoder <R , E > {
153- fn do_poll_read(
154- self : Pin <& mut Self >,
155- cx: & mut Context <' _>,
156- output: & mut PartialBuffer <& mut [ u8 ] >,
157- ) -> Poll <Result <( ) >> {
158- let mut this = self . project( ) ;
159-
160- if let ControlFlow :: Break ( res) =
161- this. inner. do_poll_read( output, & mut * this. encoder, None )
162- {
163- return Poll :: Ready ( res) ;
164- }
155+ fn do_poll_read(
156+ inner: & mut GenericEncoder ,
157+ encoder: & mut dyn EncodeV2 ,
158+ mut reader: Pin <& mut dyn AsyncBufRead >,
159+ cx: & mut Context <' _>,
160+ output: & mut WriteBuffer <' _>,
161+ ) -> Poll <Result <( ) >> {
162+ if let ControlFlow :: Break ( res) = inner. do_poll_read( output, encoder, None ) {
163+ return Poll :: Ready ( res) ;
164+ }
165165
166- loop {
167- let mut input = match this . reader. as_mut( ) . poll_fill_buf( cx) {
168- Poll :: Pending => None ,
169- Poll :: Ready ( res) => Some ( PartialBuffer :: new( res?) ) ,
170- } ;
166+ loop {
167+ let mut input = match reader. as_mut( ) . poll_fill_buf( cx) {
168+ Poll :: Pending => None ,
169+ Poll :: Ready ( res) => Some ( PartialBuffer :: new( res?) ) ,
170+ } ;
171171
172- let control_flow =
173- this. inner
174- . do_poll_read( output, & mut * this. encoder, input. as_mut( ) ) ;
172+ let control_flow = inner. do_poll_read( output, encoder, input. as_mut( ) ) ;
175173
176- let is_pending = input. is_none( ) ;
177- if let Some ( input) = input {
178- let len = input. written( ) . len( ) ;
179- this . reader. as_mut( ) . consume( len) ;
180- }
174+ let is_pending = input. is_none( ) ;
175+ if let Some ( input) = input {
176+ let len = input. written( ) . len( ) ;
177+ reader. as_mut( ) . consume( len) ;
178+ }
181179
182- if let ControlFlow :: Break ( res) = control_flow {
183- break Poll :: Ready ( res) ;
184- }
180+ if let ControlFlow :: Break ( res) = control_flow {
181+ break Poll :: Ready ( res) ;
182+ }
185183
186- if is_pending {
187- return Poll :: Pending ;
188- }
184+ if is_pending {
185+ return Poll :: Pending ;
189186 }
190187 }
191188 }
189+
190+ impl <R : AsyncBufRead , E : EncodeV2 > Encoder <R , E > {
191+ fn do_poll_read(
192+ self : Pin <& mut Self >,
193+ cx: & mut Context <' _>,
194+ output: & mut WriteBuffer <' _>,
195+ ) -> Poll <Result <( ) >> {
196+ let this = self . project( ) ;
197+
198+ do_poll_read( this. inner, this. encoder, this. reader, cx, output)
199+ }
200+ }
192201 } ;
193202}
194203pub ( crate ) use impl_encoder;
0 commit comments