History

[git-packetline] Even without pin projection lifetimes don't add up

Sebastian Thiel committed 5 years ago

Commit 7e834f51 parent b4ff4e71 file · +6 −11Browse files

Unified · Split

git-packetline/src/read/sidebands/async_io.rs+6−11
@@ -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 useful16/// 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)]
19pub struct WithSidebands<'a, T, F>18pub struct WithSidebands<'a, T, F>
20where19where
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]28impl<'a, T, F> Drop for WithSidebands<'a, T, F>
31impl<'a, T, F> PinnedDrop for WithSidebands<'a, T, F>
32where29where
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
131impl<'a, T, F> AsyncBufRead for WithSidebands<'a, T, F>127impl<'a, T, F> AsyncBufRead for WithSidebands<'a, T, F>
132where128where
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
208impl<'a, T, F> AsyncRead for WithSidebands<'a, T, F>203impl<'a, T, F> AsyncRead for WithSidebands<'a, T, F>
209where204where
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 = {