Struct winsafe::guard::CoTaskMemFreeGuard

source ·
pub struct CoTaskMemFreeGuard { /* private fields */ }
Available on crate features kernel and ole only.
Expand description

RAII implementation which automatically calls CoTaskMemFree when the object goes out of scope.

Implementations§

source§

impl CoTaskMemFreeGuard

source

pub const unsafe fn new(pmem: *mut c_void, sz: usize) -> Self

Constructs the guard.

§Safety

Be sure the pointer must be freed with CoTaskMemFree at the end of the scope, and the size is correct.

source

pub fn leak(&mut self) -> (*mut c_void, usize)

Ejects the underlying memory pointer and size, leaving null and zero in their places.

Since the internal memory pointer will be invalidated, the destructor will not run. It’s your responsibility to run it, otherwise you’ll cause a memory leak.

source

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

Returns a pointer to the allocated memory block, or null if not allocated.

source

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

Returns a mutable pointer to the allocated memory block, or null if not allocated.

source

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

Returns a slice over the allocated memory block.

source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable slice over the allocated memory block.

source

pub const unsafe fn as_slice_aligned<T>(&self) -> &[T]

Returns a slice over the allocated memory block, aligned to the given type.

§Safety

Make sure the alignment is correct.

source

pub unsafe fn as_mut_slice_aligned<T>(&mut self) -> &mut [T]

Returns a mutable slice over the allocated memory block, aligned to the given type.

§Safety

Make sure the alignment is correct.

source

pub const fn len(&self) -> usize

Returns the size of the allocated memory block.

Trait Implementations§

source§

impl Drop for CoTaskMemFreeGuard

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.