This update adds two features to improve string support and efficiency.
The HSTRING type now includes an HStringBuilder type for pre-allocating and constructing an HSTRING without requiring an additional copy. This is similar to the WindowsPreallocateStringBuffer function but implemented directly in Rust, as I did for C++/WinRT back in the day.
const HELLO: [u16; 5] = [0x48, 0x65, 0x6C, 0x6C, 0x6F];
let mut b = HStringBuilder::new(5)?;
b.copy_from_slice(&HELLO);
let h: HSTRING = b.into();
assert_eq!(&h, "Hello");
The windows-registry crate now also provide get_hstring and set_hstring for reading and writing registry values using HSTRING. This is far more efficient than either String or OsString and is lossless, while still providing convertibility with String and OsString.
key.set_hstring("key", h!("value"))?;
let value: HSTRING = key.get_hstring("key")?;
key.set_hstring("key", &value)?;
This update adds two features to improve string support and efficiency.
The
HSTRING
type now includes anHStringBuilder
type for pre-allocating and constructing anHSTRING
without requiring an additional copy. This is similar to theWindowsPreallocateStringBuffer
function but implemented directly in Rust, as I did for C++/WinRT back in the day.The
windows-registry
crate now also provideget_hstring
andset_hstring
for reading and writing registry values usingHSTRING
. This is far more efficient than eitherString
orOsString
and is lossless, while still providing convertibility withString
andOsString
.Fixes: #3119