From 87c864f28113b21a18f7f166661850186469cdc8 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 21 Mar 2023 11:14:51 +0100 Subject: [PATCH] make API more ergonomic --- tokio/src/io/async_fd.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tokio/src/io/async_fd.rs b/tokio/src/io/async_fd.rs index 65b02959571..6f698273451 100644 --- a/tokio/src/io/async_fd.rs +++ b/tokio/src/io/async_fd.rs @@ -559,7 +559,7 @@ impl AsyncFd { /// let async_fd = AsyncFd::new(socket)?; /// /// let written = async_fd - /// .async_io(Interest::WRITABLE, || async_fd.get_ref().send(&[1, 2])) + /// .async_io(Interest::WRITABLE, |inner| inner.send(&[1, 2])) /// .await?; /// /// println!("wrote {written} bytes"); @@ -596,9 +596,11 @@ impl AsyncFd { pub async fn async_io( &self, interest: Interest, - f: impl FnMut() -> io::Result, + mut f: impl FnMut(&T) -> io::Result, ) -> io::Result { - self.registration.async_io(interest, f).await + self.registration + .async_io(interest, || f(self.get_ref())) + .await } }