Struct oaidl::DroppableBString

source ·
pub struct DroppableBString { /* private fields */ }
Expand description

Struct that holds pointer to Sys* allocated memory. It will automatically free the memory via the Sys* functions unless it has been consumed.

Safety

This wraps up a pointer to Sys* allocated memory and will automatically clean up that memory correctly unless the memory has been leaked by consume().

One would use the .consume() method when sending the pointer through FFI.

If you don’t manually free the memory yourself (correctly) or send it to an FFI function that will do so, then it will be leaked memory.

If you have a memory leak and you’re using this type, then check your use of consume.

Example

extern crate oaidl;
extern crate widestring;
 
use oaidl::{BStringError, BStringExt, DroppableBString};
use widestring::U16String;
 
fn main() -> Result<(), BStringError> {
    let s = U16String::from_str("The first step to doing anything is to believe you can do it. See it finished in your mind before you ever start. It takes dark in order to show light.");
    let dbs = s.consume_to_managed_bstr()?;
    drop(dbs); // Correctly deallocates allocated memory.
    Ok(())
}

Implementations§

consume() -> *mut u16 returns the contained data while also setting a flag that the data has been consumed. It is your responsibility to manage the memory yourself. Most uses of BSTR in FFI will free the memory for you.

This method is very unsafe to use unless you know how to handle it correctly, hence the unsafe marker.

Trait Implementations§

Formats the value using the given formatter. Read more

Handles freeing the allocated BSTR correctly via SysFreeString. The only (safe) way to construct a DroppableBString is via an [allocate_managed_bstr] call.

Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

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 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.