5
0
mirror of git://git.proxmox.com/git/pxar.git synced 2025-03-19 22:50:36 +03:00

drop custom poll_fn, require rust 1.64

this was added to std in 1.64

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
(cherry picked from commit 6ad046f9f92b40413f59cc5f4c23d2bafdf141f2)
This commit is contained in:
Wolfgang Bumiller 2023-01-13 13:37:17 +01:00 committed by Fabian Grünbichler
parent a7b5a68713
commit eb2fb432a9
4 changed files with 2 additions and 43 deletions

View File

@ -5,6 +5,7 @@
#![deny(missing_docs)]
use std::ffi::OsString;
use std::future::poll_fn;
use std::io;
use std::mem::{self, size_of, size_of_val, MaybeUninit};
use std::os::unix::ffi::{OsStrExt, OsStringExt};
@ -17,7 +18,6 @@ use std::task::{Context, Poll};
use endian_trait::Endian;
use crate::format::{self, Header};
use crate::poll_fn::poll_fn;
use crate::util::{self, io_err_other};
use crate::{Entry, EntryKind, Metadata};

View File

@ -4,6 +4,7 @@
#![deny(missing_docs)]
use std::future::poll_fn;
use std::io;
use std::mem::{forget, size_of, size_of_val, take};
use std::os::unix::ffi::OsStrExt;
@ -17,7 +18,6 @@ use endian_trait::Endian;
use crate::binary_tree_array;
use crate::decoder::{self, SeqRead};
use crate::format::{self, GoodbyeItem};
use crate::poll_fn::poll_fn;
use crate::Metadata;
pub mod aio;

View File

@ -15,8 +15,6 @@ pub mod format;
pub(crate) mod util;
mod poll_fn;
pub mod accessor;
pub mod binary_tree_array;
pub mod decoder;

View File

@ -1,39 +0,0 @@
//! `poll_fn` reimplementation as it is otherwise the only thing we need from the futures crate.
//!
//! Our `futures` crate dependency is optional.
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
pub struct PollFn<F> {
func: Option<F>,
}
pub fn poll_fn<F, R>(func: F) -> PollFn<F>
where
F: FnMut(&mut Context) -> Poll<R>,
{
PollFn { func: Some(func) }
}
impl<F, R> Future for PollFn<F>
where
F: FnMut(&mut Context) -> Poll<R>,
{
type Output = R;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let this = unsafe { self.get_unchecked_mut() };
match &mut this.func {
None => panic!("poll() after Ready"),
Some(func) => {
let res = func(cx);
if res.is_ready() {
this.func = None;
}
res
}
}
}
}