mehcode / config-rs

⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Apache License 2.0
2.43k stars 206 forks source link

Add clone to builder state types #379

Closed JunichiSugiura closed 1 year ago

JunichiSugiura commented 1 year ago

This PR is to add Clone impl to both DefaultState and AsyncState. This allows ConfigBuilder to be fully clonable. My goal is to make bevy plugin that inserts ConfigBuilder as resource so that developers can query them from systems and modify (e.g. configure additional source file etc.).

I'm not 100% sure this is a right approach but it satisfied my use case for now. Let me know if there's other way to make it work.

Example

Without clone

🦄  cargo run --example cli_config
   Compiling dip v0.1.0 (/Users/js/projects/github.com/JunichiSugiura/dip)
error[E0507]: cannot move out of dereference of `dip::prelude::ResMut<'_, ConfigBuilder<DefaultState>>`
  --> examples/cli/config/main.rs:17:16
   |
17 |     *builder = builder.add_source(File::with_name("examples/cli/config/config/development"));
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `ConfigBuilder<DefaultState>`, which does not implement the `Copy` trait
JunichiSugiura commented 1 year ago

What's the status on this PR?

matthiasbeyer commented 1 year ago

Ah, thanks for pinging me!

JunichiSugiura commented 1 year ago

Thanks for the merge !

JunichiSugiura commented 1 year ago

@matthiasbeyer Hi, what's the plan for publishing a new version including this PR? This has been a blocker to bump my lib.

matthiasbeyer commented 1 year ago

Hm. Can this be considered a backwards compatible fix? I am not sure. If it is, I could release a patchlevel version update.

JunichiSugiura commented 1 year ago

@matthiasbeyer This PR just adds Clone trait so the old code still works without any changes, I think.

matthiasbeyer commented 1 year ago

Submitted backport in #398

Will release 0.13.3 with this patch shortly.

JunichiSugiura commented 1 year ago

@matthiasbeyer Thank you so much 🙏