Releases: ZihanType/rudi
Release list
v0.8.3
-
feat: support for method in
impl traitblock as constructor.now supports code like the following:
use rudi::Singleton; #[derive(Clone)] struct One(i32); #[Singleton] impl From<i32> for One { #[di] fn from(value: i32) -> Self { One(value) } }
-
fix: add
dev-dependenciesforrudi-macrocrate. -
chore: simplify the
flattenfunction. -
chore: add assertions to
doctests. -
chore: extract functions.
v0.8.2
v0.8.1
v0.8.0
In this release, there is only one breaking change and more internal improvements.
When using syn crate, parsing attributes directly to Attribute or Meta types had a lot of limitations, such as not being able to use a keyword as a Path type, value in the form of name = value could only be of expression type, and so on.
So in rudi I used Attribute::parse_nested_meta and syn::meta::parser to parse attributes manually. After writing more parsing code like this, I wanted to pull them out and turn them into a generic crate, so I implemented a from-attr crate after referring to the attribute-derive crate, which was able to fully satisfy the functionality that I needed to implement rudi, greatly reducing the code.
Breaking
-
Constructor in
impl blockneed to be annotated with#[di]. This is to allow other methods to exist in theimpl block.before:
use rudi::Transient; struct A; #[Transient] impl A { fn new() -> Self { A } // not allowed // fn hello() { // println!("Hello"); // } }
after:
use rudi::Transient; struct A; #[Transient] impl A { #[di] // <- add this fn new() -> Self { A } // allowed fn hello() { println!("Hello"); } }
Changed
rudinow usesfrom-attrcrate to parse attributes.- make the
auto_registerargument available only when theauto-registerfeature flag is enabled. This will causerust-analyzerto report an error inexamples/hello-world-with-generic, but is actually correct.
Docs
- add
#[di]used onfnofimpl blockdescription. - improve readability of documents in
Context::flushmethod.
Full Changelog: v0.7.0...v0.8.0
v0.7.0
In this release, a new scope, SingleOwner, has been added, whose constructor is run only once, and which can only get references to instances from Context, not ownership instances. Compared to the previous Singleton scope, the difference is that SingleOwner doesn't have to implement the Clone trait, and can't get ownership of instances, which is suitable for types that have high creation overhead and don't want to be cloned.
More details can be found in the all-scope example and reference example.
Feature
add SingleOwner scope.
Breaking
Rename
-
Contextallow_only_singleton_eager_create->allow_only_single_eager_createallow_only_singleton_eager_create->allow_only_single_eager_createsingleton_registry->single_registryjust_create_singleton->just_create_singlejust_create_singleton_with_name->just_create_single_with_nametry_create_singleton->try_just_create_singletry_create_singleton_with_name->try_just_create_single_with_nametry_create_singletons_by_type->try_just_create_singles_by_typejust_create_singleton_async->just_create_single_asyncjust_create_singleton_with_name_async->just_create_single_with_name_asynctry_create_singleton_async->try_just_create_single_asynctry_create_singleton_with_name_async->try_just_create_single_with_name_asynctry_create_singletons_by_type_async->try_just_create_singles_by_type_asynccontains_singleton->contains_singlecontains_singleton_with_name->contains_single_with_nameget_singleton->get_singleget_singleton_with_name->get_single_with_nameget_singleton_option->get_single_optionget_singleton_option_with_name->get_single_option_with_nameget_singletons_by_type->get_singles_by_type
-
ContextOptionsallow_only_singleton_eager_create->allow_only_single_eager_createinstance->singletoninstance_with_name->singleton_with_name
-
SingletonInstance->Single -
DynSingletonInstance->DynSingle
Add variant
Scope::SingleOwnerEagerCreateFunction::None
Change type
Definition.colortype toOption<Color>
Change
- chore: remove feature gate in auto register tests.
- chore: replace qualified path with use.
- dep: update axum 0.7.
- chore: change lint configuration through Cargo.
- chore: simplified export of attribute macros.
- docs: add README-zh_cn.md.
Added
Full Changelog: v0.6.0...v0.7.0
v0.6.0
In this release, the most important feature is support for reference types. With it, you don't have to call the clone method once every time you get a Singleton from Context, making the experience of using the framework consistent with not using it.
As mentioned above, there is a small limitation, which is that only references to Singleton are supported. This is understandable, because for a Singleton, the framework knows which value to get a reference to, but for a Transient, it doesn't know which value to get a reference to.
More details can be found in the example and doc.
Feature
- support resolve references.
Breaking
- use
#[di(option)]and#[di(vec)]without specifying a type. - rename
refreshandrefresh_asyncmethods toflushandflush_asyncinContext.
Changed
- docs: simplify first example in the attribute macro doc.
- docs: improve readability of example in the attribute macro doc.
- chore:
#[di]attribute used on a field or arguments can be duplicated
Added
Context::just_create_singletonContext::just_create_singleton_with_nameContext::try_create_singletonContext::try_create_singleton_with_nameContext::try_create_singletons_by_typeContext::just_create_singleton_asyncContext::just_create_singleton_with_name_asyncContext::try_create_singleton_asyncContext::try_create_singleton_with_name_asyncContext::try_create_singletons_by_type_async
Full Changelog: v0.5.0...v0.6.0
v0.5.0
Breaking
- move the
rudi_pathargument from#[Singleton]and#[Transient]to#[di]. - rename Feature Flag
debug-printtotracing. - change
rudi-macrodependency to optional and default.
Full Changelog: v0.4.0...v0.5.0
v0.4.0
In this release, the most important feature, is the conditional registration, with it, you can do according to environment variables or configuration files, register different Provider to the Context, detailed usage can be seen example.
Breaking
-
Visibility of
create_eager_instancesandcreate_eager_instances_asyncmethods onContextwas changed to private, userefreshandrefresh_asyncinstead. -
Remove the
idandnamemethods onResolveModule, use thetymethod instead. -
Remove the
providers_len,iterandsingletons_lenmethods onContext, useprovider_registryandsingleton_registryinstead. -
#[di(vector = T)]=>#[di(vec = T)].
Changed
- Change the visibility of
SingletonInstancetopub. - Change the visibility of the
conditionmethod on theDynProvidertopub. - Change the visibility of
EagerCreateFunctiontopub.
Added
SingletonProvider::conditionTransientProvider::conditionSingletonAsyncProvider::conditionTransientAsyncProvider::conditionContext::contains_providerContext::contains_provider_with_nameContext::refreshContext::refresh_asyncResolveModule::tyDynSingletonInstanceContext::allow_overrideContext::allow_only_singleton_eager_createContext::eager_createContext::singleton_registryContext::provider_registryContext::loaded_modulesContext::conditional_providersContext::eager_create_functionsContext::dependency_chainProvider::conditionDefinition::conditionalContext::get_singletonContext::get_singleton_with_nameContext::get_singleton_optionContext::get_singleton_option_with_nameContext::get_singletons_by_type
Full Changelog: v0.3.1...v0.4.0
v0.3.1
v0.3.0
In this release, I've continued to polish the use of attribute macros with the goal of making them more ergonomic.
Although the attribute macros have been very much refactored internally, the migration steps are simple for developers.
-
#[di(option(T))]=>#[di(option = T)] -
#[di(vector(T))]=>#[di(vector = T)] -
#[Singleton(not_auto_register)]/#[Transient(not_auto_register)]=>#[Singleton(auto_register = false)]/#[Transient(auto_register = false)] -
#[Singleton(async_constructor)]/#[Transient(async_constructor)]=>#[Singleton(async)]/#[Transient(async)] -
#[rudi(crate = path::to::rudi)]=>#[Singleton(rudi_path = path::to::rudi)]/#[Transient(rudi_path = path::to::rudi)]
For more details on how the attributes are used in the current release, see:
- https://docs.rs/rudi/latest/rudi/attr.Singleton.html#on-struct-and-function
- https://docs.rs/rudi/latest/rudi/attr.Singleton.html#on-field-of-struct-and-argument-of-function
- https://docs.rs/rudi/latest/rudi/attr.Singleton.html#struct-or-function-attributes-examples
- https://docs.rs/rudi/latest/rudi/attr.Singleton.html#field-or-argument-attributes-examples