Fix: Merge variable tables instead of bailing#102
Closed
LucasOe wants to merge 3 commits intoSuperCuber:masterfrom
LucasOe:merge-tables
Closed
Fix: Merge variable tables instead of bailing#102LucasOe wants to merge 3 commits intoSuperCuber:masterfrom LucasOe:merge-tables
LucasOe wants to merge 3 commits intoSuperCuber:masterfrom
LucasOe:merge-tables
Conversation
This allows to have nested tables for variables.
SuperCuber
reviewed
Jun 26, 2022
src/config.rs
Outdated
| for (variable_name, variable_value) in package.variables { | ||
| if first_package.variables.contains_key(&variable_name) { | ||
| anyhow::bail!("variable {:?} already encountered", variable_name); | ||
| // Panic safety: Already checked via `contains_key` above |
Owner
There was a problem hiding this comment.
This can be rewritten like so:
- if first_package.variables.contains_key(&variable_name) {
- // Panic safety: Already checked via `contains_key` above
- let mut first_value = first_package.variables.get_mut(&variable_name).unwrap();
- match (&mut first_value, &variable_value) {
+ if let Some(first_value) = first_package.variables.get_mut(&variable_name).as_mut() {
+ match (&first_value, &variable_value) {
SuperCuber
reviewed
Jun 26, 2022
src/config.rs
Outdated
| let mut first_value = first_package.variables.get_mut(&variable_name).unwrap(); | ||
| match (&mut first_value, &variable_value) { | ||
| (toml::Value::Table(_a), toml::Value::Table(_b)) => { | ||
| info!("Merging {:?} tables", variable_name); |
Owner
There was a problem hiding this comment.
this should be trace!, not info! since it shouldn't appear with just a single -v, it fits more into -vvv category.
Owner
|
See above comments and make sure to run |
Author
|
I fixed the issues mentioned above. |
Owner
|
The code could be simplified even more, I pushed a commit that implements it with the simplification. Thanks for opening the PR, I wouldn't have gotten around to it otherwise :) |
|
Yeah, me neither. (I was the OP of the other PR.) Thanks :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for #64:
This fix replaces the duplicate
merge_tablesfunction with the already existingrecursive_extend_mapfunction. I wasn't able to add unit tests because I don't know any Rust. From my testing this solution works, but please take a look at it before merging and let me know if there are any issues.