Skip to content
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

Allow the name and value in set_string to be 2 different types #3412

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

Conversation

kerosina
Copy link

@kerosina kerosina commented Jan 3, 2025

Currently, windows_registry::key::Key::set_string takes one generic type T which implements AsRef<str>, which is the type of the arguments name and value. This signature is too restrictive, since both arguments must be of the same concrete type, while it should accept, for example, key.set_string(String::from("Name"),"Value").

This PR adds a new generic type U, with the same trait bound as T and which is the type of value, thereby allowing the aforementioned situation and similar cases where the 2 arguments have different concrete types that fulfill the same trait bound.

Fixes: #3313

@kennykerr
Copy link
Collaborator

Thanks for the contribution. Is this an attempt to fix #3313?

@kerosina
Copy link
Author

kerosina commented Jan 6, 2025

Thanks for the contribution. Is this an attempt to fix #3313?

Didn't realize there already existed an issue about this. But yes, it fixes #3313

@kennykerr
Copy link
Collaborator

OK, how about the other methods mentioned in that issue like set_expand_string? Also we'd need a simple test that validates this in the test_registry crate.

@kerosina
Copy link
Author

kerosina commented Jan 6, 2025

@microsoft-github-policy-service agree


#[test]
fn string() -> Result<()> {
let test_key = "software\\windows-rs\\tests\\string";
_ = CURRENT_USER.remove_tree(test_key);
let key = CURRENT_USER.create(test_key)?;

key.set_string("string", "value")?;
key.set_string("string", Cow::Owned("lolz".to_string()))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please append the new tests rather than rewriting existing tests - that way we know the existing tested code continues to work without much reasoning.

Also, please actually test the changes before pushing a PR. 😉

"lolz" != "value"

Copy link
Author

@kerosina kerosina Jan 6, 2025

Choose a reason for hiding this comment

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

Sorry, copy pasted from rust playground and didn't realize I changed the value name.

@kerosina
Copy link
Author

kerosina commented Jan 6, 2025

BTW, I didn't update set_multi_string's signature since it would break code which passed an empty array (with an inferred type), but, if windows-registry is about to have a major version bump, do you think the tradeoff would be worth it?

@kennykerr
Copy link
Collaborator

Passing an empty array seems like a perfectly reasonable thing to do so I'd rather not break that. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[windows-registry] set_string set_expand_string and set_multi_string are hard to use
3 participants