]> git.proxmox.com Git - proxmox-backup.git/commitdiff
use pin-project to remove more unsafe blocks
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 10 Nov 2020 13:33:33 +0000 (14:33 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 12 Nov 2020 08:43:38 +0000 (09:43 +0100)
we already have it in our dependency tree, so use it

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cargo.toml
src/client/merge_known_chunks.rs

index 68d2ee3189167ebc0bfe5326448a6330f4e45389..87aa9cba6d85ee44b929a19eec727d96f057cb85 100644 (file)
@@ -46,6 +46,7 @@ pam = "0.7"
 pam-sys = "0.5"
 percent-encoding = "2.1"
 pin-utils = "0.1.0"
+pin-project = "0.4"
 pathpatterns = "0.1.2"
 proxmox = { version = "0.7.0", features = [ "sortable-macro", "api-macro", "websocket" ] }
 #proxmox = { git = "git://git.proxmox.com/git/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] }
index 1f278d32053ba55ac2d767283ac33142b3b36316..16e9ab9a93688dfc3945a5ef47927e62e20d0950 100644 (file)
@@ -3,6 +3,7 @@ use std::task::{Context, Poll};
 
 use anyhow::{Error};
 use futures::*;
+use pin_project::pin_project;
 
 use crate::backup::ChunkInfo;
 
@@ -15,7 +16,9 @@ pub trait MergeKnownChunks: Sized {
     fn merge_known_chunks(self) -> MergeKnownChunksQueue<Self>;
 }
 
+#[pin_project]
 pub struct MergeKnownChunksQueue<S> {
+    #[pin]
     input: S,
     buffer: Option<MergedChunkInfo>,
 }
@@ -39,10 +42,10 @@ where
     type Item = Result<MergedChunkInfo, Error>;
 
     fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
-        let this = unsafe { self.get_unchecked_mut() };
+        let mut this = self.project();
 
         loop {
-            match ready!(unsafe { Pin::new_unchecked(&mut this.input) }.poll_next(cx)) {
+            match ready!(this.input.as_mut().poll_next(cx)) {
                 Some(Err(err)) => return Poll::Ready(Some(Err(err))),
                 None => {
                     if let Some(last) = this.buffer.take() {
@@ -58,13 +61,13 @@ where
 
                             match last {
                                 None => {
-                                    this.buffer = Some(MergedChunkInfo::Known(list));
+                                    *this.buffer = Some(MergedChunkInfo::Known(list));
                                     // continue
                                 }
                                 Some(MergedChunkInfo::Known(mut last_list)) => {
                                     last_list.extend_from_slice(&list);
                                     let len = last_list.len();
-                                    this.buffer = Some(MergedChunkInfo::Known(last_list));
+                                    *this.buffer = Some(MergedChunkInfo::Known(last_list));
 
                                     if len >= 64 {
                                         return Poll::Ready(this.buffer.take().map(Ok));
@@ -72,7 +75,7 @@ where
                                     // continue
                                 }
                                 Some(MergedChunkInfo::New(_)) => {
-                                    this.buffer = Some(MergedChunkInfo::Known(list));
+                                    *this.buffer = Some(MergedChunkInfo::Known(list));
                                     return Poll::Ready(last.map(Ok));
                                 }
                             }
@@ -80,7 +83,7 @@ where
                         MergedChunkInfo::New(chunk_info) => {
                             let new = MergedChunkInfo::New(chunk_info);
                             if let Some(last) = this.buffer.take() {
-                                this.buffer = Some(new);
+                                *this.buffer = Some(new);
                                 return Poll::Ready(Some(Ok(last)));
                             } else {
                                 return Poll::Ready(Some(Ok(new)));