Skip to content

Commit

Permalink
feature: add into_inner
Browse files Browse the repository at this point in the history
This can always succeed, because the SliceDecoder will never implement Seek
  • Loading branch information
rklaehn committed Feb 8, 2023
1 parent 44943bd commit 2329a8f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,13 @@ mod tokio_io {
Reading(Box<SliceDecoderInner<T>>),
/// we are being polled for output
Output(Box<SliceDecoderInner<T>>),
/// we are done
Done,
/// value so we can implement take. If you see this, you've found a bug.
Taken,
}

impl<T: AsyncRead + Unpin> SliceDecoderState<T> {
fn take(&mut self) -> Self {
std::mem::replace(self, SliceDecoderState::Done)
std::mem::replace(self, SliceDecoderState::Taken)
}
}

Expand All @@ -818,6 +818,14 @@ mod tokio_io {
};
Self(SliceDecoderState::Reading(Box::new(state)))
}

pub fn into_inner(self) -> T {
match self.0 {
SliceDecoderState::Reading(state) => state.shared.input,
SliceDecoderState::Output(state) => state.shared.input,
SliceDecoderState::Taken => unreachable!(),
}
}
}

impl<T: AsyncRead + Unpin> AsyncRead for AsyncSliceDecoder<T> {
Expand Down Expand Up @@ -861,8 +869,8 @@ mod tokio_io {
};
break Poll::Ready(Ok(()));
}
SliceDecoderState::Done => {
break Poll::Ready(Ok(()));
SliceDecoderState::Taken => {
unreachable!();
}
}
}
Expand Down

0 comments on commit 2329a8f

Please sign in to comment.