Update polldance

This commit is contained in:
Aode (lion) 2022-07-22 17:38:58 -05:00
parent 42f20eb96e
commit 5d1821946c
2 changed files with 109 additions and 15 deletions

78
Cargo.lock generated
View file

@ -2,6 +2,12 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
@ -54,9 +60,9 @@ checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]]
name = "io-lifetimes"
version = "0.6.0"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a763a4311c7be6e8185a2e0b4cf1109a847dba3a10865d15170570ba007e36af"
checksum = "24c3f4eff5495aee4c0399d7b6a0dc2b6e81be84242ffbfcf253ebacccc1d0cb"
[[package]]
name = "join-all"
@ -65,26 +71,26 @@ source = "git+https://git.asonix.dog/safe-async/join-all#640069c1cbf5195ace220bd
[[package]]
name = "libc"
version = "0.2.120"
version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
name = "linux-raw-sys"
version = "0.0.42"
version = "0.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5284f00d480e1c39af34e72f8ad60b94f47007e3481cd3b731c1d67190ddc7b7"
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
[[package]]
name = "pin-project-lite"
version = "0.2.8"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "polldance"
version = "0.1.0"
source = "git+https://git.asonix.dog/safe-async/polldance#dc3f8bd0e552fa78d79a79c85921841bc587b422"
source = "git+https://git.asonix.dog/safe-async/polldance#cf88cef83966f8afcb9fff1f0fe840075fe53f2d"
dependencies = [
"rustix",
]
@ -96,24 +102,25 @@ source = "git+https://git.asonix.dog/safe-async/read-write-buf#c3a7fc23ed51f12d3
[[package]]
name = "rustix"
version = "0.34.0"
version = "0.35.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40022ca0a2a8ed0ef04033ef4ed5ed47f440a3d0aeb772bc1bb8ccf709138461"
checksum = "d51cc38aa10f6bbb377ed28197aa052aa4e2b762c22be9d3153d01822587e787"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"winapi",
"windows-sys",
]
[[package]]
name = "tokio"
version = "1.17.0"
version = "1.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e"
dependencies = [
"autocfg",
"pin-project-lite",
]
@ -138,3 +145,46 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]]
name = "windows_i686_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]]
name = "windows_i686_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]]
name = "windows_x86_64_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]]
name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"

View file

@ -205,6 +205,28 @@ impl<T: AsFd + 'static> Async<T> {
.unwrap();
}
pub async fn read_with<R>(&self, op: impl Fn(&T) -> Result<R>) -> Result<R> {
poll_fn(|cx| {
poll_nonblocking!(nonblocking((op)(&self.io)));
self.register_readable(cx);
Poll::Pending
})
.await
}
pub async fn read_with_mut<R>(&mut self, op: impl Fn(&mut T) -> Result<R>) -> Result<R> {
poll_fn(|cx| {
poll_nonblocking!(nonblocking((op)(&mut self.io)));
self.register_readable(cx);
Poll::Pending
})
.await
}
pub async fn read(&mut self, buf: &mut [u8]) -> Result<ReadBytes>
where
T: std::io::Read + Unpin,
@ -250,6 +272,28 @@ impl<T: AsFd + 'static> Async<T> {
Ok(start)
}
pub async fn write_with<R>(&self, op: impl Fn(&T) -> Result<R>) -> Result<R> {
poll_fn(|cx| {
poll_nonblocking!(nonblocking((op)(&self.io)));
self.register_writable(cx);
Poll::Pending
})
.await
}
pub async fn write_with_mut<R>(&mut self, op: impl Fn(&mut T) -> Result<R>) -> Result<R> {
poll_fn(|cx| {
poll_nonblocking!(nonblocking((op)(&mut self.io)));
self.register_writable(cx);
Poll::Pending
})
.await
}
pub async fn write(&mut self, buf: &[u8]) -> Result<usize>
where
T: std::io::Write + Unpin,
@ -527,6 +571,6 @@ where
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
(&mut self.get_mut().0)(cx)
(self.get_mut().0)(cx)
}
}