Struct BString

Source
pub struct BString(/* private fields */);
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§

Source§

impl BString

Source

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.

Source

pub fn from_cstr(s: &CStr) -> Result<BString, Utf8Error>

Converts a C-string into a BString.

Source

pub fn as_mut_ptr(&mut self) -> *mut u16

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

Source

pub fn into_ptr(self) -> *mut u16

Converts the BString into a raw pointer.

Methods from Deref<Target = BStr>§

Source

pub fn as_ptr(&self) -> *const u16

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

Source

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.

Source

pub fn len(&self) -> u32

Returns the string length in characters.

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_slice(&self) -> &[u8]

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

Source

pub fn to_string(&self) -> Result<String, FormatError>

Trait Implementations§

Source§

impl AsRef<BStr> for BString

Source§

fn as_ref(&self) -> &BStr

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

impl Borrow<BStr> for BString

Source§

fn borrow(&self) -> &BStr

Immutably borrows from an owned value. Read more
Source§

impl Clone for BString

Source§

fn clone(&self) -> BString

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BString

Source§

fn default() -> BString

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

impl Deref for BString

Source§

type Target = BStr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &BStr

Dereferences the value.
Source§

impl Drop for BString

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ExternInput<AutomationTypeSystem> for BString

Source§

type Lease = BString

Source§

type Owned = BString

Source§

unsafe fn into_foreign_parameter( self, ) -> ComResult<(Self::ForeignType, Self::Lease)>

Safety Read more
Source§

unsafe fn from_foreign_parameter( source: Self::ForeignType, ) -> ComResult<Self::Owned>

Safety Read more
Source§

impl ExternInput<RawTypeSystem> for BString

Source§

type Lease = CString

Source§

type Owned = BString

Source§

unsafe fn into_foreign_parameter( self, ) -> ComResult<(Self::ForeignType, Self::Lease)>

Safety Read more
Source§

unsafe fn from_foreign_parameter( source: Self::ForeignType, ) -> ComResult<Self::Owned>

Safety Read more
Source§

impl ExternOutput<AutomationTypeSystem> for BString

Source§

impl ExternOutput<RawTypeSystem> for BString

Source§

impl ExternType<AutomationTypeSystem> for BString

Source§

impl ExternType<RawTypeSystem> for BString

Source§

impl<'a> From<&'a str> for BString

Source§

fn from(source: &str) -> BString

Converts to this type from the input type.
Source§

impl From<BString> for IntercomString

Source§

fn from(source: BString) -> Self

Converts to this type from the input type.
Source§

impl From<String> for BString

Source§

fn from(source: String) -> BString

Converts to this type from the input type.
Source§

impl FromStr for BString

Source§

fn from_str(s: &str) -> Result<BString, Self::Err>

Converts a Rust string into a BString.

Source§

type Err = Infallible

The associated error which can be returned from parsing.
Source§

impl PartialEq for BString

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<IntercomString> for BString

Source§

type Error = ComError

The type returned in the event of a conversion error.
Source§

fn try_from(source: IntercomString) -> Result<BString, ComError>

Performs the conversion.
Source§

impl TryFrom<Variant> for BString

Source§

type Error = VariantError

The type returned in the event of a conversion error.
Source§

fn try_from(src: Variant) -> Result<BString, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ExternDefault for T

Source§

unsafe fn extern_default() -> T

Safety Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.