Open
Description
openedon 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment