Skip to content

feat(lib): merge-replace flag #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

feat(lib): merge-replace flag #39

wants to merge 7 commits into from

Conversation

evd0kim
Copy link

@evd0kim evd0kim commented May 28, 2025

Hello, for some reason we needed array replacement instead of extending them.
I suggest this PR for optional replacement of arrays provided in the inner toml.

@jdrouet
Copy link
Owner

jdrouet commented May 28, 2025

Hey! Thanks a lot for this contribution! I didn't have this need when I created this crate but I see why you'd need that!

There are a few things that I think should be done differently.

First, this introduces breaking changes. To avoid that, you could create a Merger struct with some parameters (replace_array for example), with the default parameter being the current behavior. And use the default Merger in the existing functions. That way, no breaking change 😉

Second, I know there's no contribution section to inform you about that, but I'm trying to keep conventional commits (at least for the title of the PR that will be squashed) so could you rename it accordingly?

Thanks again for your contribution, if you need some help, feel free to ask, I can jump in or even do the changes if needed.

@evd0kim
Copy link
Author

evd0kim commented May 28, 2025

@jdrouet thanks for looking into it.

I will amend PR and ping you when ready.

@evd0kim evd0kim changed the title Added replace flag, amended tests feat(lib): merge-replace flag May 29, 2025
@jdrouet
Copy link
Owner

jdrouet commented May 29, 2025

@evd0kim thanks for this update!

Could you add a set_replace_arrays(&mut self, value: bool) and not set the attribute to be pub?
Doing this will allow us to add new fields without having a breaking change.

Also, quick question: was this generated with AI?

@evd0kim
Copy link
Author

evd0kim commented May 29, 2025

HI @jdrouet. I've amended lib. I hope it works for you. I left the old interface intact and checked if public functions have the same signature.

@evd0kim
Copy link
Author

evd0kim commented May 29, 2025

Also, quick question: was this generated with AI?

Raw version yes. I will add setter.

@evd0kim
Copy link
Author

evd0kim commented May 30, 2025

Hi @jdrouet please have a look when you have a moment. I've amended Merger.

Copy link
Owner

@jdrouet jdrouet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there 😉

src/lib.rs Outdated
Comment on lines 138 to 145
pub fn merge_with_options(
value: Value,
other: Value,
replace_arrays: bool,
) -> Result<Value, Error> {
let merger = Merger::new().with_replace_arrays(replace_arrays);
merger.merge(value, other)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid introducing this function? It's not needed and is limiting considering it only takes replace_arrays parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Now it is merge_replace global function which allows merging with replacing arrays.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally don't see the difference. Merge with options could be extended with other parameters. The only advantage is backward compatibility, probably.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a merge_replace. Adding this extra shorthand might not be necessary considering the body of the function 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdrouet do you mean you don't like a public function and merging with replacement should happen via Merger instantiation and a method call? Because now I don't understand what API you'd like to see here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view, this kind of global function should have no option or a way to pass any function while not having a breaking change if a parameter is added.
If you want, you can have a merge_with_options but I don't think merge_replace has its place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I removed merge_replace and updated macro definition in tests.

@jdrouet jdrouet added the AI Generated This issue or pull request has been generated with AI label May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI Generated This issue or pull request has been generated with AI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants