Prepare for 1.0 release

This commit is contained in:
Diggory Blake 2024-07-05 17:09:05 +01:00
parent 718b8e9c90
commit 698dfa31e6
No known key found for this signature in database
GPG key ID: E6BDFA83146ABD40
5 changed files with 40 additions and 14 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "aerosol" name = "aerosol"
version = "1.0.0-alpha.9" version = "1.0.0"
authors = ["Diggory Blake <diggsey@googlemail.com>"] authors = ["Diggory Blake <diggsey@googlemail.com>"]
edition = "2018" edition = "2018"
description = "Simple dependency injection for Rust" description = "Simple dependency injection for Rust"
@ -18,7 +18,7 @@ axum-extra = ["axum", "dep:axum-extra"]
[dependencies] [dependencies]
parking_lot = "0.12.1" 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 } async-trait = { version = "0.1", optional = true }
axum = { version = "0.7.5", optional = true } axum = { version = "0.7.5", optional = true }
axum-extra = { version = "0.9.3", optional = true, features = [ axum-extra = { version = "0.9.3", optional = true, features = [

View file

@ -88,7 +88,7 @@ macro_rules! impl_async_constructible {
async fn construct_async(aero: &Aero) -> Result<Self, Self::Error> { async fn construct_async(aero: &Aero) -> Result<Self, Self::Error> {
let res = $y($t::construct_async(aero).await?); 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) Ok(res)
} }
@ -201,11 +201,9 @@ impl<R: ResourceList> Aero<R> {
/// Convert into a different variant of the Aero type. Any missing required resources /// Convert into a different variant of the Aero type. Any missing required resources
/// will be automatically asynchronously constructed. /// will be automatically asynchronously constructed.
pub async fn try_construct_remaining_async<R2: ResourceList, I>( pub async fn try_construct_remaining_async<R2, I>(self) -> anyhow::Result<Aero<R2>>
self,
) -> anyhow::Result<Aero<R2>>
where where
R2: Sculptor<R, I>, R2: Sculptor<R, I> + ResourceList,
<R2 as Sculptor<R, I>>::Remainder: AsyncConstructibleResourceList, <R2 as Sculptor<R, I>>::Remainder: AsyncConstructibleResourceList,
{ {
<<R2 as Sculptor<R, I>>::Remainder>::construct_async(&self).await?; <<R2 as Sculptor<R, I>>::Remainder>::construct_async(&self).await?;
@ -217,9 +215,9 @@ impl<R: ResourceList> Aero<R> {
/// Convert into a different variant of the Aero type. Any missing required resources /// 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. /// will be automatically asynchronously constructed. Panics if construction of any missing resource fails.
pub async fn construct_remaining_async<R2: ResourceList, I>(self) -> Aero<R2> pub async fn construct_remaining_async<R2, I>(self) -> Aero<R2>
where where
R2: Sculptor<R, I>, R2: Sculptor<R, I> + ResourceList,
<R2 as Sculptor<R, I>>::Remainder: AsyncConstructibleResourceList, <R2 as Sculptor<R, I>>::Remainder: AsyncConstructibleResourceList,
{ {
unwrap_constructed_hlist::<<R2 as Sculptor<R, I>>::Remainder, _>( unwrap_constructed_hlist::<<R2 as Sculptor<R, I>>::Remainder, _>(

View file

@ -13,6 +13,8 @@
//! a resource is required it can be accessed infallibly. The `Aero![...]` macro exists to //! 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. //! 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 //! ## Optional features
//! //!
//! ### `async` //! ### `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; pub use frunk;
#[cfg(feature = "async")] #[cfg(feature = "async")]

View file

@ -135,7 +135,7 @@ impl<R: ResourceList> Aero<R> {
Some( Some(
// Safety: all Aero variants are `#[repr(transparent)]` wrappers around // Safety: all Aero variants are `#[repr(transparent)]` wrappers around
// the same concrete type. // the same concrete type.
unsafe { std::mem::transmute(self) }, unsafe { std::mem::transmute::<&Aero<R>, &Aero<R2>>(self) },
) )
} else { } else {
None None

View file

@ -175,9 +175,9 @@ impl<R: ResourceList> Aero<R> {
/// Convert into a different variant of the Aero type. Any missing required resources /// Convert into a different variant of the Aero type. Any missing required resources
/// will be automatically constructed. /// will be automatically constructed.
pub fn try_construct_remaining<R2: ResourceList, I>(self) -> anyhow::Result<Aero<R2>> pub fn try_construct_remaining<R2, I>(self) -> anyhow::Result<Aero<R2>>
where where
R2: Sculptor<R, I>, R2: Sculptor<R, I> + ResourceList,
<R2 as Sculptor<R, I>>::Remainder: ConstructibleResourceList, <R2 as Sculptor<R, I>>::Remainder: ConstructibleResourceList,
{ {
<<R2 as Sculptor<R, I>>::Remainder>::construct(&self)?; <<R2 as Sculptor<R, I>>::Remainder>::construct(&self)?;
@ -189,9 +189,9 @@ impl<R: ResourceList> Aero<R> {
/// Convert into a different variant of the Aero type. Any missing required resources /// 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. /// will be automatically constructed. Panics if construction of any missing resource fails.
pub fn construct_remaining<R2: ResourceList, I>(self) -> Aero<R2> pub fn construct_remaining<R2, I>(self) -> Aero<R2>
where where
R2: Sculptor<R, I>, R2: Sculptor<R, I> + ResourceList,
<R2 as Sculptor<R, I>>::Remainder: ConstructibleResourceList, <R2 as Sculptor<R, I>>::Remainder: ConstructibleResourceList,
{ {
unwrap_constructed_hlist::<<R2 as Sculptor<R, I>>::Remainder, _>( unwrap_constructed_hlist::<<R2 as Sculptor<R, I>>::Remainder, _>(