From 44fe3f0e76ee22b112f6beba277cf095f77e6738 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sat, 11 Mar 2023 11:50:01 +0100 Subject: [PATCH] Make use of pin! stabilization --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ece529d..95ad175 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ //! ``` #![forbid(unsafe_code)] use std::future::Future; +use std::pin::Pin; use std::sync::Arc; use std::sync::Condvar; use std::sync::Mutex; @@ -60,10 +61,15 @@ impl Wake for CondvarWake { } /// Block on specified [`Future`]. +/// +/// The future will be polled until completion on the current thread. pub fn execute(f: impl Future) -> T { - // TODO: replace with std::pin::pin once it gets stabilized - let mut pinned = Box::pin(f); + // Use dynamic dispatch to save on codegen + poll(std::pin::pin!(f)) +} +/// Poll a future until completion. +fn poll(mut pinned: Pin<&mut dyn Future>) -> T { let wake = Arc::new(CondvarWake::default()); let waker = Waker::from(Arc::clone(&wake));