Skip to content

Commit

Permalink
use auto-enums instead of hand-rolling the future
Browse files Browse the repository at this point in the history
  • Loading branch information
problame committed Aug 24, 2023
1 parent b6bdfdb commit d8bc17d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tokio-epoll-uring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 3 additions & 34 deletions tokio-epoll-uring/src/system/submission/op_fut.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -156,42 +156,11 @@ where
}

// Used by `execute_op` to avoid boxing the future returned by the `with_submit_side` closure.
enum Fut<Output, A, B, C, D, E>
where
A: std::future::Future<Output = Output>,
B: std::future::Future<Output = Output>,
C: std::future::Future<Output = Output>,
D: std::future::Future<Output = Output>,
E: std::future::Future<Output = Output>,
{
#[auto_enums::enum_derive(Future)]
enum Fut<A, B, C, D, E> {
A(A),
B(B),
C(C),
D(D),
E(E),
}
impl<Output, A, B, C, D, E> std::future::Future for Fut<Output, A, B, C, D, E>
where
A: std::future::Future<Output = Output>,
B: std::future::Future<Output = Output>,
C: std::future::Future<Output = Output>,
D: std::future::Future<Output = Output>,
E: std::future::Future<Output = Output>,
{
type Output = Output;

fn poll(
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
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),
}
}
}
}

0 comments on commit d8bc17d

Please sign in to comment.