From 9e6a8085b35888b40319d6b97d0b42f6ec608518 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Mon, 20 Feb 2023 16:10:18 +0100 Subject: [PATCH] Revert workaround for default async methods, closes #85 --- crates/hring-buffet/src/io.rs | 80 ++++++++++++++++------------------- rust-toolchain.toml | 2 +- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/crates/hring-buffet/src/io.rs b/crates/hring-buffet/src/io.rs index 50e79f11..f63b32fc 100644 --- a/crates/hring-buffet/src/io.rs +++ b/crates/hring-buffet/src/io.rs @@ -80,55 +80,47 @@ pub trait WriteOwned { /// Write a list of buffers, re-trying the write if the kernel does a partial write. async fn writev_all(&self, list: impl Into>) -> std::io::Result<()> { - // Workaround for https://github.com/rust-lang/rust/issues/107002, - // remove after https://github.com/rust-lang/rust/pull/107013 is merged - writev_all(self, list.into()).await - } -} + // FIXME: converting into a `Vec` and _then_ into an iterator is silly, + // we can probably find a better function signature here. + let mut list: Vec<_> = list.into().into_iter().map(BufOrSlice::Buf).collect(); -/// Write a list of buffers, re-trying the write if the kernel does a partial write. -async fn writev_all( - this: &(impl WriteOwned + ?Sized), - list: Vec, -) -> std::io::Result<()> { - let mut list: Vec<_> = list.into_iter().map(BufOrSlice::Buf).collect(); - - while !list.is_empty() { - let res; - (res, list) = this.writev(list).await; - let n = res?; - - if n == 0 { - return Err(std::io::Error::new( - std::io::ErrorKind::WriteZero, - "write zero", - )); - } + while !list.is_empty() { + let res; + (res, list) = self.writev(list).await; + let n = res?; - let mut n = n; - list = list - .into_iter() - .filter_map(|item| { - if n == 0 { - Some(item) - } else { - let item_len = item.len(); - - if n >= item_len { - n -= item_len; - None - } else { - let item = item.consume(n); - n = 0; + if n == 0 { + return Err(std::io::Error::new( + std::io::ErrorKind::WriteZero, + "write zero", + )); + } + + let mut n = n; + list = list + .into_iter() + .filter_map(|item| { + if n == 0 { Some(item) + } else { + let item_len = item.len(); + + if n >= item_len { + n -= item_len; + None + } else { + let item = item.consume(n); + n = 0; + Some(item) + } } - } - }) - .collect(); - assert_eq!(n, 0); - } + }) + .collect(); + assert_eq!(n, 0); + } - Ok(()) + Ok(()) + } } enum BufOrSlice { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c84d5980..8ec5656a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-01-21" +channel = "nightly-2023-02-20" components = ["llvm-tools-preview"] \ No newline at end of file