pub trait WinStr {
// Required method
fn to_bstr(&self) -> *const u16;
// Provided method
fn to_string(&self) -> String { ... }
}
Expand description
The WinStr
trait provides methods for working with BSTRs (Binary String),
a format commonly used in Windows API. BSTRs are wide strings (UTF-16)
with specific memory layouts, used for interoperation with COM
(Component Object Model) and other Windows-based APIs.
Required Methods§
Sourcefn to_bstr(&self) -> *const u16
fn to_bstr(&self) -> *const u16
Converts a Rust string into a BSTR.
§Returns
*const u16
- A pointer to the UTF-16 encoded BSTR.
This method is implemented for &str
and String
, converting
them into BSTRs, and for *const u16
as a passthrough.
§Example
use rustclr::WinStr;
let rust_str = "Hello, World!";
let bstr_ptr = rust_str.to_bstr();
// Use the BSTR pointer in a COM function...
Provided Methods§
Sourcefn to_string(&self) -> String
fn to_string(&self) -> String
Converts a BSTR (pointer *const u16
) back to a Rust String
.
§Returns
String
- AString
containing the text from the BSTR if the trait is implemented for*const u16
. For other types, returns an emptyString
.
§Example
use rustclr::WinStr;
let bstr: *const u16 = /* assume a BSTR from COM */;
let rust_string = bstr.to_string();