Releases: ZihanType/rudi
v0.8.3
-
feat: support for method in
impl trait
block 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-dependencies
forrudi-macro
crate. -
chore: simplify the
flatten
function. -
chore: add assertions to
doctest
s. -
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 block
need 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
rudi
now usesfrom-attr
crate to parse attributes.- make the
auto_register
argument available only when theauto-register
feature flag is enabled. This will causerust-analyzer
to report an error inexamples/hello-world-with-generic
, but is actually correct.
Docs
- add
#[di]
used onfn
ofimpl block
description. - improve readability of documents in
Context::flush
method.
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
-
Context
allow_only_singleton_eager_create
->allow_only_single_eager_create
allow_only_singleton_eager_create
->allow_only_single_eager_create
singleton_registry
->single_registry
just_create_singleton
->just_create_single
just_create_singleton_with_name
->just_create_single_with_name
try_create_singleton
->try_just_create_single
try_create_singleton_with_name
->try_just_create_single_with_name
try_create_singletons_by_type
->try_just_create_singles_by_type
just_create_singleton_async
->just_create_single_async
just_create_singleton_with_name_async
->just_create_single_with_name_async
try_create_singleton_async
->try_just_create_single_async
try_create_singleton_with_name_async
->try_just_create_single_with_name_async
try_create_singletons_by_type_async
->try_just_create_singles_by_type_async
contains_singleton
->contains_single
contains_singleton_with_name
->contains_single_with_name
get_singleton
->get_single
get_singleton_with_name
->get_single_with_name
get_singleton_option
->get_single_option
get_singleton_option_with_name
->get_single_option_with_name
get_singletons_by_type
->get_singles_by_type
-
ContextOptions
allow_only_singleton_eager_create
->allow_only_single_eager_create
instance
->singleton
instance_with_name
->singleton_with_name
-
SingletonInstance
->Single
-
DynSingletonInstance
->DynSingle
Add variant
Scope::SingleOwner
EagerCreateFunction::None
Change type
Definition.color
type 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
refresh
andrefresh_async
methods toflush
andflush_async
inContext
.
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_singleton
Context::just_create_singleton_with_name
Context::try_create_singleton
Context::try_create_singleton_with_name
Context::try_create_singletons_by_type
Context::just_create_singleton_async
Context::just_create_singleton_with_name_async
Context::try_create_singleton_async
Context::try_create_singleton_with_name_async
Context::try_create_singletons_by_type_async
Full Changelog: v0.5.0...v0.6.0
v0.5.0
Breaking
- move the
rudi_path
argument from#[Singleton]
and#[Transient]
to#[di]
. - rename Feature Flag
debug-print
totracing
. - change
rudi-macro
dependency 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_instances
andcreate_eager_instances_async
methods onContext
was changed to private, userefresh
andrefresh_async
instead. -
Remove the
id
andname
methods onResolveModule
, use thety
method instead. -
Remove the
providers_len
,iter
andsingletons_len
methods onContext
, useprovider_registry
andsingleton_registry
instead. -
#[di(vector = T)]
=>#[di(vec = T)]
.
Changed
- Change the visibility of
SingletonInstance
topub
. - Change the visibility of the
condition
method on theDynProvider
topub
. - Change the visibility of
EagerCreateFunction
topub
.
Added
SingletonProvider::condition
TransientProvider::condition
SingletonAsyncProvider::condition
TransientAsyncProvider::condition
Context::contains_provider
Context::contains_provider_with_name
Context::refresh
Context::refresh_async
ResolveModule::ty
DynSingletonInstance
Context::allow_override
Context::allow_only_singleton_eager_create
Context::eager_create
Context::singleton_registry
Context::provider_registry
Context::loaded_modules
Context::conditional_providers
Context::eager_create_functions
Context::dependency_chain
Provider::condition
Definition::conditional
Context::get_singleton
Context::get_singleton_with_name
Context::get_singleton_option
Context::get_singleton_option_with_name
Context::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