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

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.

Converts a C-string into a BString.

Returns the pointer as a 16-bit wide character pointer.

Converts the BString into a raw pointer.

Methods from Deref<Target = BStr>

Returns the pointer as a 16-bit wide character pointer.

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.

Returns the string length in characters.

Gets the BStr as a slice of 16-bit characters.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Executes the destructor for this type. Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts a Rust string into a BString.

The associated error which can be returned from parsing.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Safety Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.