Skip to content

Releases: ZihanType/rudi

v0.8.3

Choose a tag to compare

@ZihanType ZihanType released this 26 Mar 14:15
  • 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 for rudi-macro crate.

  • chore: simplify the flatten function.

  • chore: add assertions to doctests.

  • chore: extract functions.

v0.8.2

Choose a tag to compare

@ZihanType ZihanType released this 08 Mar 08:16
  • chore: fix typo.
  • docs: move attribute_macro.md from rudi crate to rudi-macro crate.

v0.8.1

Choose a tag to compare

@ZihanType ZihanType released this 26 Feb 07:50
  • chore: clear clippy warning
  • feat: add Context::insert_single{ton, _owner}{_with_name} methods

v0.8.0

Choose a tag to compare

@ZihanType ZihanType released this 05 Feb 07:24

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

  1. Constructor in impl block need to be annotated with #[di]. This is to allow other methods to exist in the impl 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 uses from-attr crate to parse attributes.
  • make the auto_register argument available only when the auto-register feature flag is enabled. This will cause rust-analyzer to report an error in examples/hello-world-with-generic, but is actually correct.

Docs

  • add #[di] used on fn of impl block description.
  • improve readability of documents in Context::flush method.

Full Changelog: v0.7.0...v0.8.0

v0.7.0

Choose a tag to compare

@ZihanType ZihanType released this 06 Dec 10:34

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

  1. 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
  2. ContextOptions

    • allow_only_singleton_eager_create -> allow_only_single_eager_create
    • instance -> singleton
    • instance_with_name -> singleton_with_name
  3. SingletonInstance -> Single

  4. DynSingletonInstance -> DynSingle

Add variant

  1. Scope::SingleOwner
  2. EagerCreateFunction::None

Change type

  1. Definition.color type to Option<Color>

Change

  1. chore: remove feature gate in auto register tests.
  2. chore: replace qualified path with use.
  3. dep: update axum 0.7.
  4. chore: change lint configuration through Cargo.
  5. chore: simplified export of attribute macros.
  6. docs: add README-zh_cn.md.

Added

Full Changelog: v0.6.0...v0.7.0

v0.6.0

Choose a tag to compare

@ZihanType ZihanType released this 11 Sep 10:25

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

  1. support resolve references.

Breaking

  1. use #[di(option)] and #[di(vec)] without specifying a type.
  2. rename refresh and refresh_async methods to flush and flush_async in Context.

Changed

  1. docs: simplify first example in the attribute macro doc.
  2. docs: improve readability of example in the attribute macro doc.
  3. chore: #[di] attribute used on a field or arguments can be duplicated

Added

Full Changelog: v0.5.0...v0.6.0

v0.5.0

Choose a tag to compare

@ZihanType ZihanType released this 05 Sep 05:54

Breaking

  1. move the rudi_path argument from #[Singleton] and #[Transient] to #[di].
  2. rename Feature Flag debug-print to tracing.
  3. change rudi-macro dependency to optional and default.

Full Changelog: v0.4.0...v0.5.0

v0.4.0

Choose a tag to compare

@ZihanType ZihanType released this 29 Aug 06:45

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

  1. Visibility of create_eager_instances and create_eager_instances_async methods on Context was changed to private, use refresh and refresh_async instead.

  2. Remove the id and name methods on ResolveModule, use the ty method instead.

  3. Remove the providers_len, iter and singletons_len methods on Context, use provider_registry and singleton_registry instead.

  4. #[di(vector = T)] => #[di(vec = T)].

Changed

Added

Full Changelog: v0.3.1...v0.4.0

v0.3.1

Choose a tag to compare

@ZihanType ZihanType released this 16 Aug 03:03
  • #[Singleton] and #[Transient] can be used on enum.

v0.3.0

Choose a tag to compare

@ZihanType ZihanType released this 12 Aug 19:09

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.

  1. #[di(option(T))] => #[di(option = T)]

  2. #[di(vector(T))] => #[di(vector = T)]

  3. #[Singleton(not_auto_register)] / #[Transient(not_auto_register)] => #[Singleton(auto_register = false)] / #[Transient(auto_register = false)]

  4. #[Singleton(async_constructor)] / #[Transient(async_constructor)] => #[Singleton(async)] / #[Transient(async)]

  5. #[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: