#[repr(C)]
pub struct NSTDAllocator { pub state: NSTDAny, pub allocate: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMut, pub allocate_zeroed: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMut, pub reallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt, _: NSTDUInt) -> NSTDAllocError, pub deallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt) -> NSTDAllocError, }
Available on crate feature alloc only.
Expand description

A structure of function pointers making up an allocator VTable.

Fields§

§state: NSTDAny

An opaque pointer to the allocator’s state.

§allocate: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMut

Allocates a contiguous sequence of size bytes in memory.

If allocation fails, a null pointer is returned.

If allocation succeeds, this returns a pointer that is suitably aligned for any type with fundamental alignment, i.e., the returned pointer will be suitably aligned for max_align_t.

Allocation will fail if size is greater than NSTDInt’s max value.

Parameters:

  • NSTDUInt size - The number of bytes to allocate.

Returns

NSTDAnyMut ptr - A pointer to the allocated memory, null on error.

Safety

  • Behavior is undefined if size is zero.

  • The new memory buffer should be considered uninitialized.

§allocate_zeroed: unsafe extern "C" fn(_: NSTDAny, _: NSTDUInt) -> NSTDAnyMut

Allocates a contiguous sequence of size bytes in memory.

The initialized memory is zero-initialized.

If allocation fails, a null pointer is returned.

If allocation succeeds, this returns a pointer that is suitably aligned for any type with fundamental alignment, i.e., the returned pointer will be suitably aligned for max_align_t.

Allocation will fail if size is greater than NSTDInt’s max value.

Parameters:

  • NSTDUInt size - The number of bytes to allocate.

Returns

NSTDAnyMut ptr - A pointer to the allocated memory, null on error.

Safety

  • Behavior is undefined if size is zero.

  • The new memory buffer should be considered uninitialized.

§reallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt, _: NSTDUInt) -> NSTDAllocError

Reallocates memory that was previously allocated by this allocator.

Reallocation will fail if new_size is greater than NSTDInt’s max value.

On successful reallocation, ptr will point to the new memory location and NSTD_ALLOC_ERROR_NONE will be returned. If this is not the case and reallocation fails, the pointer will remain untouched and the appropriate error is returned.

Parameters:

  • NSTDAnyMut *ptr - A pointer to the allocated memory.

  • NSTDUInt size - The number of bytes currently allocated.

  • NSTDUInt new_size - The number of bytes to reallocate.

Returns

NSTDAllocError errc - The allocation operation error code.

Safety

  • Behavior is undefined if new_size is zero.

  • Behavior is undefined if ptr is not a value returned by this allocator.

  • size must be the same value that was used to allocate the memory buffer.

§deallocate: unsafe extern "C" fn(_: NSTDAny, _: &mut NSTDAnyMut, _: NSTDUInt) -> NSTDAllocError

Deallocates memory that was previously allocated by this allocator.

On successful deallocation, ptr will be set to null and NSTD_ALLOC_ERROR_NONE will be returned. If this is not the case and deallocation fails, the pointer will remain untouched and the appropriate error is returned.

Parameters:

  • NSTDAnyMut *ptr - A pointer to the allocated memory, once freed the pointer is set to null.

  • NSTDUInt size - The number of bytes currently allocated.

Returns

NSTDAllocError errc - The allocation operation error code.

Safety

  • Behavior is undefined if ptr is not a value returned by this allocator.

  • size must be the same value that was used to allocate the memory buffer.

Trait Implementations§

source§

impl Clone for NSTDAllocator

source§

fn clone(&self) -> NSTDAllocator

Returns a copy 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 Copy for NSTDAllocator

source§

impl Send for NSTDAllocator

Safety

The allocator’s state must be able to be safely shared between threads.

source§

impl Sync for NSTDAllocator

Safety

The allocator’s state must be able to be safely shared between threads.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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