diff --git a/crates/libs/registry/src/key.rs b/crates/libs/registry/src/key.rs index 66461daec6..9af1282a84 100644 --- a/crates/libs/registry/src/key.rs +++ b/crates/libs/registry/src/key.rs @@ -91,7 +91,7 @@ impl Key { } /// Sets the name and value in the registry key. - pub fn set_string>(&self, name: T, value: T) -> Result<()> { + pub fn set_string, U: AsRef>(&self, name: T, value: U) -> Result<()> { self.set_bytes(name, Type::String, pcwstr(value).as_bytes()) } @@ -105,7 +105,7 @@ impl Key { } /// Sets the name and value in the registry key. - pub fn set_expand_string>(&self, name: T, value: T) -> Result<()> { + pub fn set_expand_string, U: AsRef>(&self, name: T, value: U) -> Result<()> { self.set_bytes(name, Type::ExpandString, pcwstr(value).as_bytes()) } diff --git a/crates/tests/misc/registry/tests/string.rs b/crates/tests/misc/registry/tests/string.rs index 41e507b6a8..90719020f0 100644 --- a/crates/tests/misc/registry/tests/string.rs +++ b/crates/tests/misc/registry/tests/string.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use windows_registry::*; use windows_strings::*; @@ -13,6 +14,15 @@ fn string() -> Result<()> { assert_eq!(key.get_hstring("string")?, "value"); assert_eq!(key.get_multi_string("string")?, ["value".to_string()]); + key.set_string("string_different_types", Cow::Owned("value".to_string()))?; + assert_eq!(key.get_type("string_different_types")?, Type::String); + assert_eq!(key.get_string("string_different_types")?, "value"); + assert_eq!(key.get_hstring("string_different_types")?, "value"); + assert_eq!( + key.get_multi_string("string_different_types")?, + ["value".to_string()], + ); + key.set_hstring("hstring", h!("value"))?; assert_eq!(key.get_type("hstring")?, Type::String); assert_eq!(key.get_string("hstring")?, "value"); @@ -25,6 +35,18 @@ fn string() -> Result<()> { assert_eq!(key.get_hstring("expand_string")?, "value"); assert_eq!(key.get_multi_string("expand_string")?, ["value"]); + key.set_expand_string("expand_string_different_types".to_string(), "value")?; + assert_eq!( + key.get_type("expand_string_different_types")?, + Type::ExpandString + ); + assert_eq!(key.get_string("expand_string_different_types")?, "value"); + assert_eq!(key.get_hstring("expand_string_different_types")?, "value"); + assert_eq!( + key.get_multi_string("expand_string_different_types")?, + ["value"], + ); + key.set_expand_hstring("expand_hstring", h!("value"))?; assert_eq!(key.get_type("expand_hstring")?, Type::ExpandString); assert_eq!(key.get_string("expand_hstring")?, "value");