pub struct BString(_);
Expand description
An owned BSTR string Rust type.
Used for passing strings with their ownership through the COM interfaces.
BSTR
details
The BSTR
is both a length prefixed and zero terminated string with UTF-16
encoding. It is the string type widely used with Microsoft COM for
interoperability purposes.
What makes the BSTR
exotic is that the *mut u16
pointer references the
start of the string data. The length prefix is located before the pointed
value.
It is important to note that when COM servers return BSTR
strings, they
pass ownership of the string to the COM client. After this the COM client
is responsible for de-allocating the memory. Because of this it is
important that the memory allocation for BSTR
values is well defined.
On Windows this means allocating the strings using SysAllocString
or
SysAllocStringLen
methods and freeing them with SysFreeString
by
default.
Implementations
sourceimpl BString
impl BString
sourcepub unsafe fn from_ptr(ptr: *mut u16) -> BString
pub unsafe fn from_ptr(ptr: *mut u16) -> BString
Safety
The parameter must be a valid BSTR pointer. This includes both the memory layout and allocation using BSTR-compatible allocation functions.
In addition the pointer ownership moves to the BString and the pointer must not be freed outside of BString drop.
sourcepub fn as_mut_ptr(&mut self) -> *mut u16
pub fn as_mut_ptr(&mut self) -> *mut u16
Returns the pointer as a 16-bit wide character pointer.
Methods from Deref<Target = BStr>
sourcepub fn len_bytes(&self) -> u32
pub fn len_bytes(&self) -> u32
Returns the string length in bytes.
Does not include the length prefix or the terminating zero. However any zero bytes in the middle of the string are included.
pub fn is_empty(&self) -> bool
sourcepub fn as_slice(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
pub fn as_slice(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
Gets the BStr as a slice of 16-bit characters.
pub fn to_string(&self) -> Result<String, FormatError>
Trait Implementations
sourceimpl ExternInput<AutomationTypeSystem> for BString
impl ExternInput<AutomationTypeSystem> for BString
type Lease = BString
sourceunsafe fn into_foreign_parameter(
self
) -> ComResult<(Self::ForeignType, Self::Lease)>
unsafe fn into_foreign_parameter(
self
) -> ComResult<(Self::ForeignType, Self::Lease)>
Safety Read more
type Owned = BString
sourceunsafe fn from_foreign_parameter(
source: Self::ForeignType
) -> ComResult<Self::Owned>
unsafe fn from_foreign_parameter(
source: Self::ForeignType
) -> ComResult<Self::Owned>
Safety Read more
sourceimpl ExternInput<RawTypeSystem> for BString
impl ExternInput<RawTypeSystem> for BString
type Lease = CString
sourceunsafe fn into_foreign_parameter(
self
) -> ComResult<(Self::ForeignType, Self::Lease)>
unsafe fn into_foreign_parameter(
self
) -> ComResult<(Self::ForeignType, Self::Lease)>
Safety Read more
type Owned = BString
sourceunsafe fn from_foreign_parameter(
source: Self::ForeignType
) -> ComResult<Self::Owned>
unsafe fn from_foreign_parameter(
source: Self::ForeignType
) -> ComResult<Self::Owned>
Safety Read more
sourceimpl ExternOutput<AutomationTypeSystem> for BString
impl ExternOutput<AutomationTypeSystem> for BString
fn into_foreign_output(self) -> ComResult<Self::ForeignType>
sourceunsafe fn from_foreign_output(source: Self::ForeignType) -> ComResult<Self>
unsafe fn from_foreign_output(source: Self::ForeignType) -> ComResult<Self>
Safety Read more
sourceunsafe fn drop_foreign_output(source: Self::ForeignType)
unsafe fn drop_foreign_output(source: Self::ForeignType)
Safety Read more
sourceimpl ExternOutput<RawTypeSystem> for BString
impl ExternOutput<RawTypeSystem> for BString
fn into_foreign_output(self) -> ComResult<Self::ForeignType>
sourceunsafe fn from_foreign_output(source: Self::ForeignType) -> ComResult<Self>
unsafe fn from_foreign_output(source: Self::ForeignType) -> ComResult<Self>
Safety Read more
sourceunsafe fn drop_foreign_output(source: Self::ForeignType)
unsafe fn drop_foreign_output(source: Self::ForeignType)
Safety Read more
sourceimpl ExternType<AutomationTypeSystem> for BString
impl ExternType<AutomationTypeSystem> for BString
type ForeignType = BSTR
sourceimpl ExternType<RawTypeSystem> for BString
impl ExternType<RawTypeSystem> for BString
type ForeignType = *mut i8
sourceimpl From<BString> for IntercomString
impl From<BString> for IntercomString
sourceimpl TryFrom<IntercomString> for BString
impl TryFrom<IntercomString> for BString
Auto Trait Implementations
impl RefUnwindSafe for BString
impl !Send for BString
impl !Sync for BString
impl Unpin for BString
impl UnwindSafe for BString
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ExternDefault for T
impl<T> ExternDefault for T
sourceunsafe fn extern_default() -> T
unsafe fn extern_default() -> T
Safety Read more