From e9af16fe0dc4a5ae22338181fda1e9649ae47cc4 Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Fri, 5 Jul 2024 17:09:05 +0100 Subject: [PATCH] Prepare for 1.0 release --- Cargo.toml | 4 ++-- src/async_constructible.rs | 12 +++++------- src/lib.rs | 28 ++++++++++++++++++++++++++++ src/sync_constructible.rs | 8 ++++---- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 307e7dd..4e3df47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aerosol" -version = "1.0.0-alpha.9" +version = "1.0.0" authors = ["Diggory Blake "] edition = "2018" description = "Simple dependency injection for Rust" @@ -18,7 +18,7 @@ axum-extra = ["axum", "dep:axum-extra"] [dependencies] parking_lot = "0.12.1" -anymap = { version = "1.0.0-beta.2", features = ["hashbrown"] } +anymap = { package = "anymap3", version = "1.0.0", features = ["hashbrown"] } async-trait = { version = "0.1", optional = true } axum = { version = "0.7.5", optional = true } axum-extra = { version = "0.9.3", optional = true, features = [ diff --git a/src/async_constructible.rs b/src/async_constructible.rs index acdd132..6626a5a 100644 --- a/src/async_constructible.rs +++ b/src/async_constructible.rs @@ -88,7 +88,7 @@ macro_rules! impl_async_constructible { async fn construct_async(aero: &Aero) -> Result { let res = $y($t::construct_async(aero).await?); - <$t as IndirectlyAsyncConstructible>::after_construction_async(&res, aero).await?; + <$t as IndirectlyAsyncConstructible>::after_construction_async(&res as &(dyn Any + Send + Sync), aero).await?; Ok(res) } @@ -201,11 +201,9 @@ impl Aero { /// Convert into a different variant of the Aero type. Any missing required resources /// will be automatically asynchronously constructed. - pub async fn try_construct_remaining_async( - self, - ) -> anyhow::Result> + pub async fn try_construct_remaining_async(self) -> anyhow::Result> where - R2: Sculptor, + R2: Sculptor + ResourceList, >::Remainder: AsyncConstructibleResourceList, { <>::Remainder>::construct_async(&self).await?; @@ -217,9 +215,9 @@ impl Aero { /// Convert into a different variant of the Aero type. Any missing required resources /// will be automatically asynchronously constructed. Panics if construction of any missing resource fails. - pub async fn construct_remaining_async(self) -> Aero + pub async fn construct_remaining_async(self) -> Aero where - R2: Sculptor, + R2: Sculptor + ResourceList, >::Remainder: AsyncConstructibleResourceList, { unwrap_constructed_hlist::<>::Remainder, _>( diff --git a/src/lib.rs b/src/lib.rs index ff86ad3..ef4caca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,8 @@ //! a resource is required it can be accessed infallibly. The `Aero![...]` macro exists to //! easily name an `Aero` with a specific set of required resources. //! +//! Cloning or type casting an `Aero` type is cheap (equivalent to cloning an `Arc`). +//! //! ## Optional features //! //! ### `async` @@ -122,6 +124,32 @@ //! } //! } //! ``` +//! +//! ## Implementation details +//! +//! The `Aero` type manages shared ownership of a map from resource types to "slots". +//! For a given resource type, the corresponding "slot" can be in one of three state: +//! 1) Absent. +//! No instance of this resource is present in the map. +//! 2) Present. +//! An instance of this resource exists in the map and can be accessed immediately. +//! 3) Under construction. +//! An instance of this resource is currently under construction, and may be accessed +//! once construction has finished. +//! The slot maintains a list of threads or tasks waiting for this resource to be +//! constructed, and will wake them when the resource becomes available. +//! +//! Resources can be constructed synchronously, or (when the feature is enabled) asynchronously. +//! +//! If a resource is accessed whilst under construction, the caller will wait for construction +//! to complete. The caller determines whether the wait occurs synchronously or asynchronously, +//! depending on whether `obtain()` or `obtain_async()` is used. +//! +//! It is possible (and allowed) for a thread to synchronously wait on a resource being constructed +//! asynchronously in a task, or for a task to asynchronously wait on a resource being synchronously +//! constructed on a thread. +//! + pub use frunk; #[cfg(feature = "async")] diff --git a/src/sync_constructible.rs b/src/sync_constructible.rs index aa81728..bdb6500 100644 --- a/src/sync_constructible.rs +++ b/src/sync_constructible.rs @@ -175,9 +175,9 @@ impl Aero { /// Convert into a different variant of the Aero type. Any missing required resources /// will be automatically constructed. - pub fn try_construct_remaining(self) -> anyhow::Result> + pub fn try_construct_remaining(self) -> anyhow::Result> where - R2: Sculptor, + R2: Sculptor + ResourceList, >::Remainder: ConstructibleResourceList, { <>::Remainder>::construct(&self)?; @@ -189,9 +189,9 @@ impl Aero { /// Convert into a different variant of the Aero type. Any missing required resources /// will be automatically constructed. Panics if construction of any missing resource fails. - pub fn construct_remaining(self) -> Aero + pub fn construct_remaining(self) -> Aero where - R2: Sculptor, + R2: Sculptor + ResourceList, >::Remainder: ConstructibleResourceList, { unwrap_constructed_hlist::<>::Remainder, _>(