From 5478002dda7edfd56a6f91d57fba7269115bbff7 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Fri, 26 Mar 2021 17:59:58 -0700 Subject: [PATCH] Simplify state juggling (cherry picked from commit 5bd1ba570bb1fde3b1d2e0e72e09d343f14006cb) --- quinn-proto/src/connection/streams/recv.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/quinn-proto/src/connection/streams/recv.rs b/quinn-proto/src/connection/streams/recv.rs index 3681ab500..8a54a50d1 100644 --- a/quinn-proto/src/connection/streams/recv.rs +++ b/quinn-proto/src/connection/streams/recv.rs @@ -240,14 +240,12 @@ impl<'a> Chunks<'a> { /// /// Should call finalize() when done calling this. pub fn next(&mut self, max_length: usize) -> Result, ReadError> { - let mut rs = match mem::replace(&mut self.state, ChunksState::Finalized) { - ChunksState::Readable(rs) => rs, + let rs = match self.state { + ChunksState::Readable(ref mut rs) => rs, ChunksState::Reset(error_code) => { - self.state = ChunksState::Reset(error_code); return Err(ReadError::Reset(error_code)); } ChunksState::Finished => { - self.state = ChunksState::Finished; return Ok(None); } ChunksState::Finalized => panic!("must not call next() after finalize()"), @@ -255,7 +253,6 @@ impl<'a> Chunks<'a> { if let Some(chunk) = rs.assembler.read(max_length, self.ordered) { self.read += chunk.bytes.len() as u64; - self.state = ChunksState::Readable(rs); return Ok(Some(chunk)); } @@ -276,7 +273,6 @@ impl<'a> Chunks<'a> { // retrying a read harmlessly re-traces our steps back to returning // `Err(Blocked)` again. The buffers can't refill and the stream's own state // can't change so long as this `Chunks` exists. - self.state = ChunksState::Readable(rs); Err(ReadError::Blocked) } }