-
-
Notifications
You must be signed in to change notification settings - Fork 281
chore: refactor how get_unrecognized_keys
is handled to enable unused config detection
#1967
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
chore: refactor how get_unrecognized_keys
is handled to enable unused config detection
#1967
Conversation
martin/src/cog/config.rs
Outdated
fn get_unrecognized(&self) -> &UnrecognizedValues { | ||
&self.unrecognized | ||
fn get_unrecognized_keys(&self) -> UnrecognizedKeys { | ||
self.unrecognized.keys().cloned().collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to clone it in every fn? Why not just return the ref to the original, and if needed, the caller can do the .keys().cloned().collect()
on the result of the get_unrecognized()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need this to be owned as otherwise this trait does not work on every level (think enums, or a struct with two sub-structs).
Especially at the top level this otherwise does not work
I considered an iterator (I can chain them, not owned) but this neither works nicely with the prefixes, nor enums.
I doubt that cloning for the warning case is a huge issue.
This is one malloc/free per warning more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the handling of unrecognized configuration keys by changing the API from returning references to values to returning owned collections of just the keys. The change addresses limitations with the previous approach where merging unrecognized values was difficult and unnecessary data was being passed around.
Key changes:
- Replace
get_unrecognized() -> &UnrecognizedValues
withget_unrecognized_keys() -> UnrecognizedKeys
- Remove the
is_default()
method from theConfigExtras
trait since it was always returningtrue
- Update documentation for
SourceConfigExtras
methods to clarify their purpose
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
martin/src/config.rs | Adds UnrecognizedKeys type alias and updates copy_unrecognized_config to work with keys only |
martin/src/file_config.rs | Removes is_default() method, updates trait methods, and adds documentation for SourceConfigExtras |
martin/src/pg/config.rs | Updates finalize() method to return UnrecognizedKeys instead of UnrecognizedValues |
martin/src/pmtiles/config.rs | Removes is_default() implementation and updates get_unrecognized to get_unrecognized_keys |
martin/src/mbtiles/config.rs | Updates trait implementation and adds missing parse_urls() method |
martin/src/cog/config.rs | Updates trait implementation to return keys instead of values reference |
martin/src/styles/config.rs | Updates trait implementation to return keys instead of values reference |
martin/src/sprites/config.rs | Updates trait implementation to return keys instead of values reference |
41dcd8c
to
dabe4c8
Compare
for more information, see https://pre-commit.ci
get_unrecognized_keys
is handledget_unrecognized_keys
is handled to enable unused config detection
During #1926 I noticed that the way we currently handle this is not super working out.
get_unrecognized(&self) -> &UnrecognizedValues
is not owned => if I need to merge, this is not quite possibleUnrecognizedValues
is not quite the information that I need. If I just need the keys, we should just ship around the keysis_default
related to this is alwaystrue
.