Struct winsafe::guard::HeapFreeGuard

source ·
pub struct HeapFreeGuard<'a, H>
where H: kernel_Hheap,
{ /* private fields */ }
Available on crate feature kernel only.
Expand description

RAII implementation for the memory allocated by HHEAP::HeapAlloc which automatically calls HeapFree when the object goes out of scope.

Implementations§

source§

impl<'a, H> HeapFreeGuard<'a, H>
where H: kernel_Hheap,

source

pub const unsafe fn new(hheap: &'a H, pmem: *mut c_void, sz: usize) -> Self

Constructs the guard by taking ownership of the handle.

§Safety

Be sure the handle must be freed with HeapFree at the end of scope, the pointer is valid, 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<'a, H> Drop for HeapFreeGuard<'a, H>
where H: kernel_Hheap,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, H> Freeze for HeapFreeGuard<'a, H>

§

impl<'a, H> RefUnwindSafe for HeapFreeGuard<'a, H>
where H: RefUnwindSafe,

§

impl<'a, H> !Send for HeapFreeGuard<'a, H>

§

impl<'a, H> !Sync for HeapFreeGuard<'a, H>

§

impl<'a, H> Unpin for HeapFreeGuard<'a, H>

§

impl<'a, H> UnwindSafe for HeapFreeGuard<'a, H>
where H: RefUnwindSafe,

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.