Conversation
This was referenced Jan 22, 2025
Contributor
This example would be great in the README (so it shows up in the crate documentation on docs.rs). |
Collaborator
Author
|
Done - thanks for the suggestion! |
ChrisDenton
previously approved these changes
Jan 22, 2025
Collaborator
ChrisDenton
left a comment
There was a problem hiding this comment.
This is a really nice API! The extensibility is a nice feature too as it'll make future feature requests much easier to accommodate.
riverar
reviewed
Jan 22, 2025
Collaborator
Author
|
@riverar - good feedback but I'd rather not add features opportunistically. If and when such needs present themselves, we can now more easily introduce them. |
riverar
reviewed
Jan 22, 2025
Co-authored-by: Rafael Rivera <rafael@withinwindows.com>
riverar
approved these changes
Jan 22, 2025
Merged
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.
Rather than adding more registry creation methods to satisfy #3269, #3346, or any future needs, this update introduces an
OpenOptionstype modeled afterstd::fs::OpenOptions. This new type provides the options and flags that you can set in order to configure how a registry key is opened. TheKeytype continues to provide thecreateandopenmethods as a convenience but internally they now also useOpenOptionsfor construction. Let's consider a few examples.Today you can use
createto create or open a registry key for read and write access:What if you only want to open the key if it already exists? Well you can use
openinstead but it offers only read access:This is where you can use the new
optionsmethod to gain more control:This opens the subkey with write access but only if it already exists. The call will fail if the key does not exist. Want to create the key in all cases? Just set the
createoption:You can also optionally create a
Transactionobject for transactional access to the registry:Failure to commit the transaction will cause all changes to be rolled back when the transaction object is dropped. They are also not observable outside of the transaction until and unless
commitis called.Finally, I removed the
Defaultimplementation from theKeyobject. This just seemed confusing as you could try (and fail) to use the various registry functions on an invalid registry key handle. If for some reason you need to hold on to an invalid registry key you can still use the unsafefrom_rawmethod.Fixes: #3269
Fixes: #3346