use pin-project to remove more unsafe blocks
we already have it in our dependency tree, so use it Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
294466ee61
commit
5d1d0f5d6c
@ -46,6 +46,7 @@ pam = "0.7"
|
|||||||
pam-sys = "0.5"
|
pam-sys = "0.5"
|
||||||
percent-encoding = "2.1"
|
percent-encoding = "2.1"
|
||||||
pin-utils = "0.1.0"
|
pin-utils = "0.1.0"
|
||||||
|
pin-project = "0.4"
|
||||||
pathpatterns = "0.1.2"
|
pathpatterns = "0.1.2"
|
||||||
proxmox = { version = "0.7.0", features = [ "sortable-macro", "api-macro", "websocket" ] }
|
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" ] }
|
#proxmox = { git = "git://git.proxmox.com/git/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] }
|
||||||
|
@ -3,6 +3,7 @@ use std::task::{Context, Poll};
|
|||||||
|
|
||||||
use anyhow::{Error};
|
use anyhow::{Error};
|
||||||
use futures::*;
|
use futures::*;
|
||||||
|
use pin_project::pin_project;
|
||||||
|
|
||||||
use crate::backup::ChunkInfo;
|
use crate::backup::ChunkInfo;
|
||||||
|
|
||||||
@ -15,7 +16,9 @@ pub trait MergeKnownChunks: Sized {
|
|||||||
fn merge_known_chunks(self) -> MergeKnownChunksQueue<Self>;
|
fn merge_known_chunks(self) -> MergeKnownChunksQueue<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pin_project]
|
||||||
pub struct MergeKnownChunksQueue<S> {
|
pub struct MergeKnownChunksQueue<S> {
|
||||||
|
#[pin]
|
||||||
input: S,
|
input: S,
|
||||||
buffer: Option<MergedChunkInfo>,
|
buffer: Option<MergedChunkInfo>,
|
||||||
}
|
}
|
||||||
@ -39,10 +42,10 @@ where
|
|||||||
type Item = Result<MergedChunkInfo, Error>;
|
type Item = Result<MergedChunkInfo, Error>;
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
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 {
|
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))),
|
Some(Err(err)) => return Poll::Ready(Some(Err(err))),
|
||||||
None => {
|
None => {
|
||||||
if let Some(last) = this.buffer.take() {
|
if let Some(last) = this.buffer.take() {
|
||||||
@ -58,13 +61,13 @@ where
|
|||||||
|
|
||||||
match last {
|
match last {
|
||||||
None => {
|
None => {
|
||||||
this.buffer = Some(MergedChunkInfo::Known(list));
|
*this.buffer = Some(MergedChunkInfo::Known(list));
|
||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
Some(MergedChunkInfo::Known(mut last_list)) => {
|
Some(MergedChunkInfo::Known(mut last_list)) => {
|
||||||
last_list.extend_from_slice(&list);
|
last_list.extend_from_slice(&list);
|
||||||
let len = last_list.len();
|
let len = last_list.len();
|
||||||
this.buffer = Some(MergedChunkInfo::Known(last_list));
|
*this.buffer = Some(MergedChunkInfo::Known(last_list));
|
||||||
|
|
||||||
if len >= 64 {
|
if len >= 64 {
|
||||||
return Poll::Ready(this.buffer.take().map(Ok));
|
return Poll::Ready(this.buffer.take().map(Ok));
|
||||||
@ -72,7 +75,7 @@ where
|
|||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
Some(MergedChunkInfo::New(_)) => {
|
Some(MergedChunkInfo::New(_)) => {
|
||||||
this.buffer = Some(MergedChunkInfo::Known(list));
|
*this.buffer = Some(MergedChunkInfo::Known(list));
|
||||||
return Poll::Ready(last.map(Ok));
|
return Poll::Ready(last.map(Ok));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +83,7 @@ where
|
|||||||
MergedChunkInfo::New(chunk_info) => {
|
MergedChunkInfo::New(chunk_info) => {
|
||||||
let new = MergedChunkInfo::New(chunk_info);
|
let new = MergedChunkInfo::New(chunk_info);
|
||||||
if let Some(last) = this.buffer.take() {
|
if let Some(last) = this.buffer.take() {
|
||||||
this.buffer = Some(new);
|
*this.buffer = Some(new);
|
||||||
return Poll::Ready(Some(Ok(last)));
|
return Poll::Ready(Some(Ok(last)));
|
||||||
} else {
|
} else {
|
||||||
return Poll::Ready(Some(Ok(new)));
|
return Poll::Ready(Some(Ok(new)));
|
||||||
|
Loading…
Reference in New Issue
Block a user