diff options
author | 2025-02-21 01:48:09 +0100 | |
---|---|---|
committer | 2025-02-21 01:48:09 +0100 | |
commit | 0f9934b1a70cdadb9131b68b6dfb76083f014636 (patch) | |
tree | 13bc41ff41acd313dc23c8bb0b50680319d15565 | |
parent | c12beecd387ad57eef434b64598473f613e32f57 (diff) | |
download | iced-0f9934b1a70cdadb9131b68b6dfb76083f014636.tar.gz iced-0f9934b1a70cdadb9131b68b6dfb76083f014636.tar.bz2 iced-0f9934b1a70cdadb9131b68b6dfb76083f014636.zip |
Leverage new `AsyncFn` traits in `stream` module
-rw-r--r-- | futures/src/stream.rs | 18 | ||||
-rw-r--r-- | futures/src/subscription.rs | 2 |
2 files changed, 7 insertions, 13 deletions
diff --git a/futures/src/stream.rs b/futures/src/stream.rs index 72e1f04b..ee9c0c14 100644 --- a/futures/src/stream.rs +++ b/futures/src/stream.rs @@ -8,13 +8,10 @@ use futures::stream::{self, Stream, StreamExt}; /// This is a more ergonomic [`stream::unfold`], which allows you to go /// from the "world of futures" to the "world of streams" by simply looping /// and publishing to an async channel from inside a [`Future`]. -pub fn channel<T, F>( +pub fn channel<T>( size: usize, - f: impl FnOnce(mpsc::Sender<T>) -> F, -) -> impl Stream<Item = T> -where - F: Future<Output = ()>, -{ + f: impl AsyncFnOnce(mpsc::Sender<T>), +) -> impl Stream<Item = T> { let (sender, receiver) = mpsc::channel(size); let runner = stream::once(f(sender)).filter_map(|_| async { None }); @@ -24,13 +21,10 @@ where /// Creates a new [`Stream`] that produces the items sent from a [`Future`] /// that can fail to the [`mpsc::Sender`] provided to the closure. -pub fn try_channel<T, E, F>( +pub fn try_channel<T, E>( size: usize, - f: impl FnOnce(mpsc::Sender<T>) -> F, -) -> impl Stream<Item = Result<T, E>> -where - F: Future<Output = Result<(), E>>, -{ + f: impl AsyncFnOnce(mpsc::Sender<T>) -> Result<(), E>, +) -> impl Stream<Item = Result<T, E>> { let (sender, receiver) = mpsc::channel(size); let runner = stream::once(f(sender)).filter_map(|result| async { diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index 3577d19f..f799d5f8 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -161,7 +161,7 @@ impl<T> Subscription<T> { /// } /// /// fn some_worker() -> impl Stream<Item = Event> { - /// stream::channel(100, |mut output| async move { + /// stream::channel(100, async |mut output| { /// // Create channel /// let (sender, mut receiver) = mpsc::channel(100); /// |