From 9ceb467e6e12129b42d67a4a1ff3cb21bc7daadd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 21 Feb 2025 01:22:56 +0100 Subject: Run `cargo fmt` --- futures/src/backend/native/tokio.rs | 2 +- futures/src/event.rs | 2 +- futures/src/keyboard.rs | 2 +- futures/src/runtime.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'futures/src') diff --git a/futures/src/backend/native/tokio.rs b/futures/src/backend/native/tokio.rs index c38ef566..0fd5da41 100644 --- a/futures/src/backend/native/tokio.rs +++ b/futures/src/backend/native/tokio.rs @@ -22,9 +22,9 @@ impl crate::Executor for Executor { pub mod time { //! Listen and react to time. + use crate::MaybeSend; use crate::core::time::{Duration, Instant}; use crate::subscription::Subscription; - use crate::MaybeSend; use futures::stream; use std::future::Future; diff --git a/futures/src/event.rs b/futures/src/event.rs index 72ea78ad..bd75d82c 100644 --- a/futures/src/event.rs +++ b/futures/src/event.rs @@ -1,8 +1,8 @@ //! Listen to runtime events. +use crate::MaybeSend; use crate::core::event::{self, Event}; use crate::core::window; use crate::subscription::{self, Subscription}; -use crate::MaybeSend; /// Returns a [`Subscription`] to all the ignored runtime events. /// diff --git a/futures/src/keyboard.rs b/futures/src/keyboard.rs index 35f6b6fa..036edb9c 100644 --- a/futures/src/keyboard.rs +++ b/futures/src/keyboard.rs @@ -1,9 +1,9 @@ //! Listen to keyboard events. +use crate::MaybeSend; use crate::core; use crate::core::event; use crate::core::keyboard::{Event, Key, Modifiers}; use crate::subscription::{self, Subscription}; -use crate::MaybeSend; /// Listens to keyboard key presses and calls the given function /// to map them into actual messages. diff --git a/futures/src/runtime.rs b/futures/src/runtime.rs index 157e2c67..0f30b469 100644 --- a/futures/src/runtime.rs +++ b/futures/src/runtime.rs @@ -2,7 +2,7 @@ use crate::subscription; use crate::{BoxFuture, BoxStream, Executor, MaybeSend}; -use futures::{channel::mpsc, Sink}; +use futures::{Sink, channel::mpsc}; use std::marker::PhantomData; /// A batteries-included runtime of commands and subscriptions. -- cgit From c12beecd387ad57eef434b64598473f613e32f57 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 21 Feb 2025 01:41:42 +0100 Subject: Remove unnecessary `Future` imports --- futures/src/backend/native/async_std.rs | 1 - futures/src/backend/native/smol.rs | 1 - futures/src/backend/native/thread_pool.rs | 1 - futures/src/backend/native/tokio.rs | 2 -- futures/src/backend/null.rs | 1 - futures/src/executor.rs | 2 -- futures/src/stream.rs | 2 -- 7 files changed, 10 deletions(-) (limited to 'futures/src') diff --git a/futures/src/backend/native/async_std.rs b/futures/src/backend/native/async_std.rs index 86714f45..be258b26 100644 --- a/futures/src/backend/native/async_std.rs +++ b/futures/src/backend/native/async_std.rs @@ -1,5 +1,4 @@ //! An `async-std` backend. -use futures::Future; /// An `async-std` executor. #[derive(Debug)] diff --git a/futures/src/backend/native/smol.rs b/futures/src/backend/native/smol.rs index 8d448e7f..9ac6a27d 100644 --- a/futures/src/backend/native/smol.rs +++ b/futures/src/backend/native/smol.rs @@ -1,5 +1,4 @@ //! A `smol` backend. -use futures::Future; /// A `smol` executor. #[derive(Debug)] diff --git a/futures/src/backend/native/thread_pool.rs b/futures/src/backend/native/thread_pool.rs index c96f2682..a90cc53a 100644 --- a/futures/src/backend/native/thread_pool.rs +++ b/futures/src/backend/native/thread_pool.rs @@ -1,5 +1,4 @@ //! A `ThreadPool` backend. -use futures::Future; /// A thread pool executor for futures. pub type Executor = futures::executor::ThreadPool; diff --git a/futures/src/backend/native/tokio.rs b/futures/src/backend/native/tokio.rs index 0fd5da41..911d788c 100644 --- a/futures/src/backend/native/tokio.rs +++ b/futures/src/backend/native/tokio.rs @@ -1,5 +1,4 @@ //! A `tokio` backend. -use futures::Future; /// A `tokio` executor. pub type Executor = tokio::runtime::Runtime; @@ -27,7 +26,6 @@ pub mod time { use crate::subscription::Subscription; use futures::stream; - use std::future::Future; /// Returns a [`Subscription`] that produces messages at a set interval. /// diff --git a/futures/src/backend/null.rs b/futures/src/backend/null.rs index 609b8b3f..f31415b9 100644 --- a/futures/src/backend/null.rs +++ b/futures/src/backend/null.rs @@ -1,5 +1,4 @@ //! A backend that does nothing! -use futures::Future; /// An executor that drops all the futures, instead of spawning them. #[derive(Debug)] diff --git a/futures/src/executor.rs b/futures/src/executor.rs index 3b0d4af1..9c14a2c9 100644 --- a/futures/src/executor.rs +++ b/futures/src/executor.rs @@ -1,8 +1,6 @@ //! Choose your preferred executor to power a runtime. use crate::MaybeSend; -use futures::Future; - /// A type that can run futures. pub trait Executor: Sized { /// Creates a new [`Executor`]. diff --git a/futures/src/stream.rs b/futures/src/stream.rs index af2f8c99..72e1f04b 100644 --- a/futures/src/stream.rs +++ b/futures/src/stream.rs @@ -2,8 +2,6 @@ use futures::channel::mpsc; use futures::stream::{self, Stream, StreamExt}; -use std::future::Future; - /// Creates a new [`Stream`] that produces the items sent from a [`Future`] /// to the [`mpsc::Sender`] provided to the closure. /// -- cgit From 0f9934b1a70cdadb9131b68b6dfb76083f014636 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 21 Feb 2025 01:48:09 +0100 Subject: Leverage new `AsyncFn` traits in `stream` module --- futures/src/stream.rs | 18 ++++++------------ futures/src/subscription.rs | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'futures/src') 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( +pub fn channel( size: usize, - f: impl FnOnce(mpsc::Sender) -> F, -) -> impl Stream -where - F: Future, -{ + f: impl AsyncFnOnce(mpsc::Sender), +) -> impl Stream { 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( +pub fn try_channel( size: usize, - f: impl FnOnce(mpsc::Sender) -> F, -) -> impl Stream> -where - F: Future>, -{ + f: impl AsyncFnOnce(mpsc::Sender) -> Result<(), E>, +) -> impl Stream> { 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 Subscription { /// } /// /// fn some_worker() -> impl Stream { - /// stream::channel(100, |mut output| async move { + /// stream::channel(100, async |mut output| { /// // Create channel /// let (sender, mut receiver) = mpsc::channel(100); /// -- cgit