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

[windows-registry] set_string set_expand_string and set_multi_string are hard to use #3313

Open
Link1J opened this issue Oct 6, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Link1J
Copy link

Link1J commented Oct 6, 2024

Suggestion

set_string set_expand_string and set_multi_string only accept one generic type. This can make them hard to use, as it means the name and value need to use the same string type. Can it be changed so that they have two generic types, one for name and another for value?


New Signatures:

fn set_string<T: AsRef<str>, V: AsRef<str>>(&self, name: T, value: V) -> Result<()>;
fn set_expand_string<T: AsRef<str>, V: AsRef<str>>(&self, name: T, value: V) -> Result<()>;
fn set_multi_string<T: AsRef<str>, V: AsRef<str>>(&self, name: T, value: &[V]) -> Result<()>;

Note

set_multi_string does not accept an empty array easily with this signature.


I came across a problem with code like this.

let order_key = windows_registry::LOCAL_MACHINE.create(r"SYSTEM\CurrentControlSet\Control\NetworkProvider\Order").unwrap();
let mut providers = order_key.get_multi_string("ProviderOrder").unwrap();
providers.push("TestThing".into());
order_key.set_multi_string("ProviderOrder", &providers).unwrap();

It was causing an error (E0308), because providers was a Vec<String> and the generic type T was &str.
I fixed by adding .to_string() after "ProviderOrder". I feel like that is bad rust code, but it was the easiest way to fix it.

@Link1J Link1J added the enhancement New feature or request label Oct 6, 2024
@kennykerr
Copy link
Collaborator

Thanks for the suggestion!

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

No branches or pull requests

2 participants