-
-
Notifications
You must be signed in to change notification settings - Fork 314
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
Config access uses impl Key
to allow type-safe keys
#1236
Conversation
impl Key
to allow structured keysimpl Key
to allow type-safe keys
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.
Thanks for sharing your amazing progress!
Before I can look at anything in detail, I'd need the commits split up so that…
- …the
Key
related changes ingix-config
are in one commit, whose subject is prefixed withfix!:
orfeat!:
. Please write the subject and body so they can go into the changelog. - …all other changes to adapt to this change can go into its own commit without any special message requirements.
There is also this one big request of only modifying the string_by_key
based access with the new trait. After all, the natural way of accessing the API is by passing triplets of section, subsection and 'key' (definitely open to a better term here).
That way, only string_by_key()
has to change at all and that change would probably be compatible to most existing uses depending on the available implementations of Key
for &BStr
for example. I don't think there is a need to break the world here, and hope this could even work without making any breaking change.
Is that feasible at all?
Is the purpose simply to have a
I was thinking we should keep the API surface small by removing all the |
No, the purpose is to have a changelog that applies to the That takes priority over each commit being green on CI, it's all trade-offs.
Thanks for sharing your thoughts. For a plumbing crate, it would already be more than fine. However, it's exposed in But since you would be touching all of these methods anyway, let's encourage the use of the potentially typesafe and nicer API by making their methods the shorter ones. This means, for example, to keep I hope all that makes sense, please do let me know about any concern you might have as well. |
f1d7e94
to
00f7c28
Compare
86e5f83
to
819d7eb
Compare
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.
Thanks so much for the changes!
It's wonderful to see how the standard-API of gix-config
can be enhanced by the Key
trait. While looking at it more closely, I also noticed something else that I think can be fixed without too much overhead.
But if that work should ever appear overwhelming or boring because the API surface is quite massive, please let me know and I can help doing the refactoring. The last thing I'd want is for you to get exhausted due to all these comments of mine 😅.
Just let me know how I can help and I will try to make it happen.
Thanks again!
As a note, I plan to finish this PR myself once I get a chance. |
Conflicts --------- gix-config/src/file/init/from_env.rs gix-config/src/parse/mod.rs gix/src/config/cache/access.rs gix/src/config/cache/incubate.rs gix/src/config/overrides.rs gix/src/repository/index.rs
006e661
to
45d9709
Compare
- reorganize `Key` trait implementation - make it possible to use it as reference (and thus re-use the impl when passing it to another function that takes a `Key` - make it less wasteful to obtain the parts of a Key - where possible, rename methods to `*_by`, while the original method is replaced by one that uses a `key: impl AsKey` instead. That way, the methods that are easiest to call are the shortest ones, while still providing the ones that take tuples like before.
The content of this PR was merged to main, but I forgot to push before changing the commit message, hence GitHub doesn't see the merge happened. Thanks again for getting this started! |
This PR changes the API of
gix_config::File
to use a trait (gix_config::Key) as key when requesting or setting configuration. This will allowgix
to use its tree of structured and validating typed keys (gix::config::tree::sections::*
) as keys directly, and also means that consumers of thegix
crate to use type-safe config access. gix-config also provides an implementation for &str and &bstr so that constant strings can be used as keys. This is part of the work addressing #1125.The PR is draft, as there remains various question marks, see specific comments in code below.
gix contains a lot of strings and
format!()
operations that could be changed to use type-safe keys, but that is left for a separate PR.Tasks
as_config_key()
)key
parametersvalue_name
instead to be in sync withKeyRef::value_name
, also seekeys()
methods