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
1515 /// An implementor of [`AsyncBufRead`] yielding packet lines on each call to [`read_line()`][AsyncBufRead::read_line()].
1616 /// It's also possible to hide the underlying packet lines using the [`Read`][AsyncRead] implementation which is useful
1717 /// if they represent binary data, like the one of a pack file.
18−#[pin_project::pin_project(PinnedDrop)]
1918 pub struct WithSidebands<'a, T, F>
2019 where
2120 T: AsyncRead,
2221 {
23− #[pin]
2422 state: State<'a, T>,
2523 handle_progress: Option<F>,
2624 pos: usize,
2725 cap: usize,
2826 }
2927
30−#[pin_project::pinned_drop]
31−impl<'a, T, F> PinnedDrop for WithSidebands<'a, T, F>
28+impl<'a, T, F> Drop for WithSidebands<'a, T, F>
3229 where
3330 T: AsyncRead,
3431 {
35− fn drop(mut self: Pin<&mut Self>) {
36− let this = self.project();
37− if let State::Idle { parent } = this.state.get_mut() {
32+ fn drop(&mut self) {
33+ if let State::Idle { parent } = self.state {
3834 parent.reset();
3935 }
4036 }
@@ -131,7 +127,7 @@ where · 90 unmodified lines
131127 impl<'a, T, F> AsyncBufRead for WithSidebands<'a, T, F>
132128 where
133129 T: AsyncRead + Unpin + Send,
134− F: FnMut(bool, &[u8]),
130+ F: FnMut(bool, &[u8]) + Unpin,
135131 {
136132 fn poll_fill_buf(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<&[u8]>> {
137133 use futures_lite::FutureExt;
@@ -200,15 +196,14 @@ where · 62 unmodified lines
200196 }
201197
202198 fn consume(self: Pin<&mut Self>, amt: usize) {
203− let this = self.project();
204− *this.pos = std::cmp::min(*this.pos + amt, *this.cap);
199+ self.pos = std::cmp::min(self.pos + amt, self.cap);
205200 }
206201 }
207202
208203 impl<'a, T, F> AsyncRead for WithSidebands<'a, T, F>
209204 where
210205 T: AsyncRead + Unpin + Send,
211− F: FnMut(bool, &[u8]),
206+ F: FnMut(bool, &[u8]) + Unpin,
212207 {
213208 fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<std::io::Result<usize>> {
214209 let nread = {