Unified · Split
| @@ -15,26 +15,22 @@ type ReadLineResult<'a> = Option<std::io::Result<Result<PacketLine<'a>, decode:: · 14 unmodified lines | |||
| 15 | /// An implementor of [`AsyncBufRead`] yielding packet lines on each call to [`read_line()`][AsyncBufRead::read_line()]. | 15 | /// An implementor of [`AsyncBufRead`] yielding packet lines on each call to [`read_line()`][AsyncBufRead::read_line()]. |
| 16 | /// It's also possible to hide the underlying packet lines using the [`Read`][AsyncRead] implementation which is useful | 16 | /// It's also possible to hide the underlying packet lines using the [`Read`][AsyncRead] implementation which is useful |
| 17 | /// if they represent binary data, like the one of a pack file. | 17 | /// if they represent binary data, like the one of a pack file. |
| 18 | #[pin_project::pin_project(PinnedDrop)] | ||
| 19 | pub struct WithSidebands<'a, T, F> | 18 | pub struct WithSidebands<'a, T, F> |
| 20 | where | 19 | where |
| 21 | T: AsyncRead, | 20 | T: AsyncRead, |
| 22 | { | 21 | { |
| 23 | #[pin] | ||
| 24 | state: State<'a, T>, | 22 | state: State<'a, T>, |
| 25 | handle_progress: Option<F>, | 23 | handle_progress: Option<F>, |
| 26 | pos: usize, | 24 | pos: usize, |
| 27 | cap: usize, | 25 | cap: usize, |
| 28 | } | 26 | } |
| 29 | 27 | ||
| 30 | #[pin_project::pinned_drop] | 28 | impl<'a, T, F> Drop for WithSidebands<'a, T, F> |
| 31 | impl<'a, T, F> PinnedDrop for WithSidebands<'a, T, F> | ||
| 32 | where | 29 | where |
| 33 | T: AsyncRead, | 30 | T: AsyncRead, |
| 34 | { | 31 | { |
| 35 | fn drop(mut self: Pin<&mut Self>) { | 32 | fn drop(&mut self) { |
| 36 | let this = self.project(); | 33 | if let State::Idle { parent } = self.state { |
| 37 | if let State::Idle { parent } = this.state.get_mut() { | ||
| 38 | parent.reset(); | 34 | parent.reset(); |
| 39 | } | 35 | } |
| 40 | } | 36 | } |
| @@ -131,7 +127,7 @@ where · 90 unmodified lines | |||
| 131 | impl<'a, T, F> AsyncBufRead for WithSidebands<'a, T, F> | 127 | impl<'a, T, F> AsyncBufRead for WithSidebands<'a, T, F> |
| 132 | where | 128 | where |
| 133 | T: AsyncRead + Unpin + Send, | 129 | T: AsyncRead + Unpin + Send, |
| 134 | F: FnMut(bool, &[u8]), | 130 | F: FnMut(bool, &[u8]) + Unpin, |
| 135 | { | 131 | { |
| 136 | fn poll_fill_buf(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<&[u8]>> { | 132 | fn poll_fill_buf(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<&[u8]>> { |
| 137 | use futures_lite::FutureExt; | 133 | use futures_lite::FutureExt; |
| @@ -200,15 +196,14 @@ where · 62 unmodified lines | |||
| 200 | } | 196 | } |
| 201 | 197 | ||
| 202 | fn consume(self: Pin<&mut Self>, amt: usize) { | 198 | fn consume(self: Pin<&mut Self>, amt: usize) { |
| 203 | let this = self.project(); | 199 | self.pos = std::cmp::min(self.pos + amt, self.cap); |
| 204 | *this.pos = std::cmp::min(*this.pos + amt, *this.cap); | ||
| 205 | } | 200 | } |
| 206 | } | 201 | } |
| 207 | 202 | ||
| 208 | impl<'a, T, F> AsyncRead for WithSidebands<'a, T, F> | 203 | impl<'a, T, F> AsyncRead for WithSidebands<'a, T, F> |
| 209 | where | 204 | where |
| 210 | T: AsyncRead + Unpin + Send, | 205 | T: AsyncRead + Unpin + Send, |
| 211 | F: FnMut(bool, &[u8]), | 206 | F: FnMut(bool, &[u8]) + Unpin, |
| 212 | { | 207 | { |
| 213 | fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<std::io::Result<usize>> { | 208 | fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<std::io::Result<usize>> { |
| 214 | let nread = { | 209 | let nread = { |