KEMBAR78
Allow name and value types in `set_string` to differ by kerosina · Pull Request #3412 · microsoft/windows-rs · GitHub
Skip to content

Conversation

@kerosina
Copy link
Contributor

@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
Contributor 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
Contributor Author

kerosina commented Jan 6, 2025

@microsoft-github-policy-service agree

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
Contributor 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
Contributor 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. 😊

@kennykerr
Copy link
Collaborator

Please run cargo fmt --all

@kennykerr kennykerr changed the title Allow the name and value in set_string to be 2 different types Allow name and value types in set_string to differ Jan 7, 2025
Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

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

Thanks!

@kennykerr kennykerr merged commit ec062c2 into microsoft:master Jan 8, 2025
75 checks passed
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