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§
source§impl DroppableBString
impl DroppableBString
sourcepub unsafe fn consume(&mut self) -> *mut u16
pub unsafe fn consume(&mut self) -> *mut u16
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§
source§impl Debug for DroppableBString
impl Debug for DroppableBString
source§impl Drop for DroppableBString
impl Drop for DroppableBString
source§fn drop(&mut self)
fn drop(&mut self)
Handles freeing the allocated BSTR correctly via SysFreeString
.
The only (safe) way to construct a DroppableBString
is via
an [allocate_managed_bstr
] call.
source§impl Hash for DroppableBString
impl Hash for DroppableBString
source§impl PartialEq<DroppableBString> for DroppableBString
impl PartialEq<DroppableBString> for DroppableBString
source§fn eq(&self, other: &DroppableBString) -> bool
fn eq(&self, other: &DroppableBString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<DroppableBString> for DroppableBString
impl PartialOrd<DroppableBString> for DroppableBString
source§fn partial_cmp(&self, other: &DroppableBString) -> Option<Ordering>
fn partial_cmp(&self, other: &DroppableBString) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for DroppableBString
impl StructuralEq for DroppableBString
impl StructuralPartialEq for DroppableBString
Auto Trait Implementations§
impl RefUnwindSafe for DroppableBString
impl !Send for DroppableBString
impl !Sync for DroppableBString
impl Unpin for DroppableBString
impl UnwindSafe for DroppableBString
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, F> TryConvert<T, F> for Twhere
T: From<T>,
F: Fail,
impl<T, F> TryConvert<T, F> for Twhere T: From<T>, F: Fail,
source§fn try_convert(val: T) -> Result<T, F>
fn try_convert(val: T) -> Result<T, F>
Blanket TryConvert implementation wherever a From