Struct libnghttp2_sys::nghttp2_mem

source ·
#[repr(C)]
pub struct nghttp2_mem { pub mem_user_data: *mut c_void, pub malloc: nghttp2_malloc, pub free: nghttp2_free, pub calloc: nghttp2_calloc, pub realloc: nghttp2_realloc, }
Expand description

@struct

Custom memory allocator functions and user defined pointer. The |mem_user_data| member is passed to each allocator function. This can be used, for example, to achieve per-session memory pool.

In the following example code, my_malloc, my_free, my_calloc and my_realloc are the replacement of the standard allocators malloc, free, calloc and realloc respectively::

void *my_malloc_cb(size_t size, void *mem_user_data) {
  return my_malloc(size);
}

void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); }

void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) {
  return my_calloc(nmemb, size);
}

void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) {
  return my_realloc(ptr, size);
}

void session_new() {
  nghttp2_session *session;
  nghttp2_session_callbacks *callbacks;
  nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb,
                     my_realloc_cb};

  ...

  nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem);

  ...
}

Fields§

§mem_user_data: *mut c_void

An arbitrary user supplied data. This is passed to each allocator function.

§malloc: nghttp2_malloc

Custom allocator function to replace malloc().

§free: nghttp2_free

Custom allocator function to replace free().

§calloc: nghttp2_calloc

Custom allocator function to replace calloc().

§realloc: nghttp2_realloc

Custom allocator function to replace realloc().

Trait Implementations§

source§

impl Clone for nghttp2_mem

source§

fn clone(&self) -> nghttp2_mem

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 Debug for nghttp2_mem

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for nghttp2_mem

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> ToOwned for T
where 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 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.