From d8bc17d9a7c90bb8954a397a1a3897a11b47c6f7 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Thu, 24 Aug 2023 20:18:27 +0200 Subject: [PATCH] use auto-enums instead of hand-rolling the future --- Cargo.lock | 24 ++++++++++++ tokio-epoll-uring/Cargo.toml | 1 + .../src/system/submission/op_fut.rs | 37 ++----------------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f78f5a..6c55d59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,6 +119,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "auto_enums" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4ba50b181a898ce52142184e3a46641002b3b190bf5ef827eb3c578fad4b70" +dependencies = [ + "derive_utils", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -487,6 +499,17 @@ dependencies = [ "serde", ] +[[package]] +name = "derive_utils" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9abcad25e9720609ccb3dcdb795d845e37d8ce34183330a9f48b03a1a71c8e21" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "either" version = "1.9.0" @@ -1610,6 +1633,7 @@ name = "tokio-epoll-uring" version = "0.1.0" dependencies = [ "assert-panic", + "auto_enums", "futures", "io-uring 0.6.0", "nix 0.26.2", diff --git a/tokio-epoll-uring/Cargo.toml b/tokio-epoll-uring/Cargo.toml index 8e96817..3155af6 100644 --- a/tokio-epoll-uring/Cargo.toml +++ b/tokio-epoll-uring/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/neondatabase/tokio-epoll-uring" license = "MIT OR Apache-2.0" [dependencies] +auto_enums = "0.8.2" futures = "0.3.28" io-uring = "0.6.0" once_cell = "1.18.0" diff --git a/tokio-epoll-uring/src/system/submission/op_fut.rs b/tokio-epoll-uring/src/system/submission/op_fut.rs index 3f5faa7..da5ddad 100644 --- a/tokio-epoll-uring/src/system/submission/op_fut.rs +++ b/tokio-epoll-uring/src/system/submission/op_fut.rs @@ -1,4 +1,4 @@ -use std::{fmt::Display, pin::Pin, sync::Arc}; +use std::{fmt::Display, sync::Arc}; /// An io_uring operation and the resources it operates on. /// @@ -156,42 +156,11 @@ where } // Used by `execute_op` to avoid boxing the future returned by the `with_submit_side` closure. -enum Fut -where - A: std::future::Future, - B: std::future::Future, - C: std::future::Future, - D: std::future::Future, - E: std::future::Future, -{ +#[auto_enums::enum_derive(Future)] +enum Fut { A(A), B(B), C(C), D(D), E(E), } -impl std::future::Future for Fut -where - A: std::future::Future, - B: std::future::Future, - C: std::future::Future, - D: std::future::Future, - E: std::future::Future, -{ - type Output = Output; - - fn poll( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll { - unsafe { - match self.get_unchecked_mut() { - Self::A(x) => Pin::new_unchecked(x).poll(cx), - Self::B(x) => Pin::new_unchecked(x).poll(cx), - Self::C(x) => Pin::new_unchecked(x).poll(cx), - Self::D(x) => Pin::new_unchecked(x).poll(cx), - Self::E(x) => Pin::new_unchecked(x).poll(cx), - } - } - } -}