From c9f8a3a2fed60ee5d7eb29b50b61480f5e7922ab Mon Sep 17 00:00:00 2001 From: Asa Paparo Date: Thu, 17 Jul 2025 03:29:52 -0400 Subject: [PATCH] reorg --- .gitignore | 2 ++ Cargo.lock | 17 ++++++++++++++++- Cargo.toml | 2 +- futures-combinators/Cargo.toml | 13 +++++++++++++ .../src}/join.rs | 9 +++++---- futures-combinators/src/lib.rs | 1 + futures-core/Cargo.toml | 11 +++++++++++ .../src/future.rs => futures-core/src/lib.rs | 10 ---------- futures-util/Cargo.toml | 12 ++++++++++++ futures-util/src/lib.rs | 13 +++++++++++++ .../utils => futures-util/src}/maybe_done.rs | 2 +- {futures/src/utils => futures-util/src}/mod.rs | 0 12 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 futures-combinators/Cargo.toml rename {futures/src/combinators => futures-combinators/src}/join.rs (98%) create mode 100644 futures-combinators/src/lib.rs create mode 100644 futures-core/Cargo.toml rename futures/src/future.rs => futures-core/src/lib.rs (75%) create mode 100644 futures-util/Cargo.toml create mode 100644 futures-util/src/lib.rs rename {futures/src/utils => futures-util/src}/maybe_done.rs (98%) rename {futures/src/utils => futures-util/src}/mod.rs (100%) diff --git a/.gitignore b/.gitignore index dfe6f47..c03eb0a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ !rustfmt.toml !/futures/ !/futures/** +!/futures-*/ +!/futures-*/** diff --git a/Cargo.lock b/Cargo.lock index c53121e..e1e463e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,5 +3,20 @@ version = 4 [[package]] -name = "futures" +name = "futures-combinators" version = "0.1.0" +dependencies = [ + "futures-core", + "futures-util", +] + +[[package]] +name = "futures-core" +version = "0.1.0" + +[[package]] +name = "futures-util" +version = "0.1.0" +dependencies = [ + "futures-core", +] diff --git a/Cargo.toml b/Cargo.toml index e07d4b3..58236df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "3" -members = [ "futures" ] +members = [ "futures-combinators", "futures-core", "futures-util"] [workspace.package] version = "0.1.0" diff --git a/futures-combinators/Cargo.toml b/futures-combinators/Cargo.toml new file mode 100644 index 0000000..9b15105 --- /dev/null +++ b/futures-combinators/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "futures-combinators" +version.workspace = true +rust-version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true + +[dependencies] +futures-core = { path = "../futures-core" } +futures-util = { path = "../futures-util" } diff --git a/futures/src/combinators/join.rs b/futures-combinators/src/join.rs similarity index 98% rename from futures/src/combinators/join.rs rename to futures-combinators/src/join.rs index b565d2a..8e70bb6 100644 --- a/futures/src/combinators/join.rs +++ b/futures-combinators/src/join.rs @@ -1,7 +1,5 @@ -use crate::{ - future::{ScopedFuture, Wake}, - utils::{MaybeDone, maybe_done}, -}; +use futures_core::{ScopedFuture, Wake}; +use futures_util::{MaybeDone, maybe_done}; use std::mem; use std::{pin::Pin, sync::atomic::Ordering}; use std::{sync::atomic::AtomicBool, task::Poll}; @@ -63,10 +61,12 @@ pub trait Join<'scope> { /// This function returns a new future which polls all futures concurrently. fn join(self) -> Self::Future; } + struct WakeStore<'scope> { parent: Option<&'scope dyn Wake<'scope>>, ready: AtomicBool, } + impl<'scope> WakeStore<'scope> { fn new() -> Self { Self { @@ -78,6 +78,7 @@ impl<'scope> WakeStore<'scope> { self.ready.swap(false, Ordering::SeqCst) } } + impl<'scope> Wake<'scope> for WakeStore<'scope> { fn wake(&self) { self.ready.swap(true, Ordering::SeqCst); diff --git a/futures-combinators/src/lib.rs b/futures-combinators/src/lib.rs new file mode 100644 index 0000000..670b0d2 --- /dev/null +++ b/futures-combinators/src/lib.rs @@ -0,0 +1 @@ +mod join; diff --git a/futures-core/Cargo.toml b/futures-core/Cargo.toml new file mode 100644 index 0000000..10964cb --- /dev/null +++ b/futures-core/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "futures-core" +version.workspace = true +rust-version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true + +[dependencies] diff --git a/futures/src/future.rs b/futures-core/src/lib.rs similarity index 75% rename from futures/src/future.rs rename to futures-core/src/lib.rs index dea5f6e..69b0e0b 100644 --- a/futures/src/future.rs +++ b/futures-core/src/lib.rs @@ -36,19 +36,9 @@ pub trait Wake<'scope> { /// what occurs in `core::task::Future::poll()` is that the ref to a cx.waker /// is cloned and stored by a reactor via some method. /// -/// /// The waker is no longer tied to the actual future's lifetime, making it /// unsound to not have either static tasks or reference counting. /// To avoid this, we want to use a &'scope waker instead, with 1 waker / task. -/// -/// If waker is ownable/cloneable, that erases the lifetime's importance. -/// If the waker is a non clonable mutable reference that lives for 'scope, -/// it cannot be passed into `poll` every time the future is polled, instead it -/// must only be registered once, leading to a register_waker api that is very -/// cumbersome without unsafe poll/unsafe register_waker. Instead, it's easier -/// to use a non clonable immutable reference and have waking occur via -/// interior mutability (this is fine since combinators rely on interior -/// mutability anyway for a 1 parent : many children waker relationship) pub trait ScopedFuture<'scope> { type Output; diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml new file mode 100644 index 0000000..1e2abc0 --- /dev/null +++ b/futures-util/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "futures-util" +version.workspace = true +rust-version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true + +[dependencies] +futures-core = { path = "../futures-core" } diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs new file mode 100644 index 0000000..7c166fa --- /dev/null +++ b/futures-util/src/lib.rs @@ -0,0 +1,13 @@ +mod maybe_done; + +use futures_core::ScopedFuture; +pub use maybe_done::*; + +// Just a helper function to ensure the futures we're returning all have the +// right implementations. +pub(crate) fn assert_future<'scope, T, F>(future: F) -> F +where + F: ScopedFuture<'scope, Output = T>, +{ + future +} diff --git a/futures/src/utils/maybe_done.rs b/futures-util/src/maybe_done.rs similarity index 98% rename from futures/src/utils/maybe_done.rs rename to futures-util/src/maybe_done.rs index d5fa7c3..e2deaa8 100644 --- a/futures/src/utils/maybe_done.rs +++ b/futures-util/src/maybe_done.rs @@ -1,6 +1,6 @@ //! Definition of the MaybeDone combinator -use crate::future::{ScopedFuture, Wake}; +use futures_core::{ScopedFuture, Wake}; use super::assert_future; use core::mem; diff --git a/futures/src/utils/mod.rs b/futures-util/src/mod.rs similarity index 100% rename from futures/src/utils/mod.rs rename to futures-util/src/mod.rs -- 2.51.2