30
30
T : AsyncRead ,
31
31
{
32
32
fn drop ( & mut self ) {
33
- if let State :: Idle { parent } = self . state {
34
- parent. reset ( ) ;
33
+ if let State :: Idle { ref mut parent } = self . state {
34
+ parent. as_mut ( ) . unwrap ( ) . reset ( ) ;
35
35
}
36
36
}
37
37
}
43
43
/// Create a new instance with the given provider as `parent`.
44
44
pub fn new ( parent : & ' a mut StreamingPeekableIter < T > ) -> Self {
45
45
WithSidebands {
46
- state : State :: Idle { parent } ,
46
+ state : State :: Idle { parent : Some ( parent ) } ,
47
47
handle_progress : None ,
48
48
pos : 0 ,
49
49
cap : 0 ,
53
53
54
54
enum State < ' a , T > {
55
55
Idle {
56
- parent : & ' a mut StreamingPeekableIter < T > ,
56
+ parent : Option < & ' a mut StreamingPeekableIter < T > > ,
57
57
} ,
58
58
ReadLine {
59
59
read_line : Pin < Box < dyn Future < Output = ReadLineResult < ' a > > + ' a > > ,
72
72
/// being true in case the `text` is to be interpreted as error.
73
73
pub fn with_progress_handler ( parent : & ' a mut StreamingPeekableIter < T > , handle_progress : F ) -> Self {
74
74
WithSidebands {
75
- state : State :: Idle { parent } ,
75
+ state : State :: Idle { parent : Some ( parent ) } ,
76
76
handle_progress : Some ( handle_progress) ,
77
77
pos : 0 ,
78
78
cap : 0 ,
82
82
/// Create a new instance without a progress handler.
83
83
pub fn without_progress_handler ( parent : & ' a mut StreamingPeekableIter < T > ) -> Self {
84
84
WithSidebands {
85
- state : State :: Idle { parent } ,
85
+ state : State :: Idle { parent : Some ( parent ) } ,
86
86
handle_progress : None ,
87
87
pos : 0 ,
88
88
cap : 0 ,
@@ -92,14 +92,14 @@ where
92
92
/// Forwards to the parent [StreamingPeekableIter::reset_with()]
93
93
pub fn reset_with ( & mut self , delimiters : & ' static [ PacketLine < ' static > ] ) {
94
94
if let State :: Idle { ref mut parent } = self . state {
95
- parent. reset_with ( delimiters)
95
+ parent. as_mut ( ) . unwrap ( ) . reset_with ( delimiters)
96
96
}
97
97
}
98
98
99
99
/// Forwards to the parent [StreamingPeekableIter::stopped_at()]
100
100
pub fn stopped_at ( & self ) -> Option < PacketLine < ' static > > {
101
101
match self . state {
102
- State :: Idle { ref parent } => parent. stopped_at ,
102
+ State :: Idle { ref parent } => parent. as_ref ( ) . unwrap ( ) . stopped_at ,
103
103
_ => None ,
104
104
}
105
105
}
@@ -113,7 +113,7 @@ where
113
113
/// next on a call to [`read_line()`][io::BufRead::read_line()].
114
114
pub async fn peek_data_line ( & mut self ) -> Option < std:: io:: Result < Result < & [ u8 ] , crate :: decode:: Error > > > {
115
115
match self . state {
116
- State :: Idle { ref mut parent } => match parent. peek_line ( ) . await {
116
+ State :: Idle { ref mut parent } => match parent. as_mut ( ) . unwrap ( ) . peek_line ( ) . await {
117
117
Some ( Ok ( Ok ( crate :: PacketLine :: Data ( line) ) ) ) => Some ( Ok ( Ok ( line) ) ) ,
118
118
Some ( Ok ( Err ( err) ) ) => Some ( Ok ( Err ( err) ) ) ,
119
119
Some ( Err ( err) ) => Some ( Err ( err) ) ,
@@ -133,19 +133,21 @@ where
133
133
use futures_lite:: FutureExt ;
134
134
use std:: io;
135
135
{
136
- let this = self . get_mut ( ) ;
136
+ let this = self . as_mut ( ) . get_mut ( ) ;
137
137
if this. pos >= this. cap {
138
138
let ( ofs, cap) = loop {
139
139
match this. state {
140
140
State :: Idle { ref mut parent } => {
141
+ let parent = parent. take ( ) . unwrap ( ) ;
142
+ let inactive = parent as * mut _ ;
141
143
this. state = State :: ReadLine {
142
144
read_line : parent. read_line ( ) . boxed ( ) ,
143
- parent_inactive : * parent as * mut _ ,
145
+ parent_inactive : inactive ,
144
146
}
145
147
}
146
148
State :: ReadLine {
147
149
ref mut read_line,
148
- parent_inactive,
150
+ parent_inactive : _ ,
149
151
} => {
150
152
let line = match ready ! ( read_line. poll( cx) ) {
151
153
Some ( line) => line?. map_err ( |err| io:: Error :: new ( io:: ErrorKind :: Other , err) ) ?,
@@ -189,14 +191,15 @@ where
189
191
}
190
192
}
191
193
let range = self . pos ..self . cap ;
192
- match self . state {
193
- State :: Idle { parent } => Poll :: Ready ( Ok ( & parent. buf [ range] ) ) ,
194
+ match self . get_mut ( ) . state {
195
+ State :: Idle { ref parent } => Poll :: Ready ( Ok ( & parent. as_ref ( ) . unwrap ( ) . buf [ range] ) ) ,
194
196
State :: ReadLine { .. } => unreachable ! ( "at least in theory" ) ,
195
197
}
196
198
}
197
199
198
200
fn consume ( self : Pin < & mut Self > , amt : usize ) {
199
- self . pos = std:: cmp:: min ( self . pos + amt, self . cap ) ;
201
+ let this = self . get_mut ( ) ;
202
+ this. pos = std:: cmp:: min ( this. pos + amt, this. cap ) ;
200
203
}
201
204
}
202
205
0 commit comments