[][src]Trait allocator_suite::allocators::global::global_switchable_allocator::GlobalSwitchableAllocator

pub trait GlobalSwitchableAllocator: Sync + GlobalAlloc + Alloc + Allocator {
    type CoroutineLocalAllocator: LocalAllocator;
    type ThreadLocalAllocator: LocalAllocator;
    type GlobalAllocator: Allocator;
    fn replace_coroutine_local_allocator(
        &self,
        replacement: Option<Self::CoroutineLocalAllocator>
    ) -> Option<Self::CoroutineLocalAllocator>;
fn initialize_thread_local_allocator(
        &self,
        thread_local_allocator: Self::ThreadLocalAllocator
    );
fn drop_thread_local_allocator(&self);
fn save_current_allocator_in_use(&self) -> CurrentAllocatorInUse;
fn restore_current_allocator_in_use(
        &self,
        restore_to: CurrentAllocatorInUse
    );
fn coroutine_local_allocator(
        &self
    ) -> Option<&Self::CoroutineLocalAllocator>;
fn thread_local_allocator(&self) -> Option<&Self::ThreadLocalAllocator>;
fn global_allocator(&self) -> &Self::GlobalAllocator; fn replace_current_allocator_in_use(
        &self,
        replacement: CurrentAllocatorInUse
    ) -> CurrentAllocatorInUse { ... }
fn callback_with_coroutine_local_allocator<R>(
        &self,
        callback: impl FnOnce() -> R
    ) -> R { ... }
fn callback_with_thread_local_allocator<R>(
        &self,
        callback: impl FnOnce() -> R
    ) -> R { ... }
fn callback_with_global_allocator<R>(
        &self,
        callback: impl FnOnce() -> R
    ) -> R { ... }
fn callback_with_different_current_allocator<R>(
        &self,
        different: CurrentAllocatorInUse,
        callback: impl FnOnce() -> R
    ) -> R { ... }
fn coroutine_local_allocator_unchecked(
        &self
    ) -> &Self::CoroutineLocalAllocator { ... }
fn thread_local_allocator_unchecked(&self) -> &Self::ThreadLocalAllocator { ... } }

A trait that all such allocators implement.

Create a new instance using the macro switchable_allocator.

Associated Types

type CoroutineLocalAllocator: LocalAllocator

Type of the coroutine local allocator.

type ThreadLocalAllocator: LocalAllocator

Type of the thread local allocator.

type GlobalAllocator: Allocator

Type of the global allocator.

Loading content...

Required methods

fn replace_coroutine_local_allocator(
    &self,
    replacement: Option<Self::CoroutineLocalAllocator>
) -> Option<Self::CoroutineLocalAllocator>

Swaps the coroutine local allocator.

Used before calling a coroutine.

Used after calling a coroutine.

fn initialize_thread_local_allocator(
    &self,
    thread_local_allocator: Self::ThreadLocalAllocator
)

Initializes the thread local allocator.

fn drop_thread_local_allocator(&self)

Drops the thread local allocator.

Panics in debug if no thread local allocator has been initialized with initialize_thread_local_allocator().

Could be made hidden by using a destructor with libc::pthread_key_create() for an otherwise unused key.

fn save_current_allocator_in_use(&self) -> CurrentAllocatorInUse

Save the current allocator in use.

fn restore_current_allocator_in_use(&self, restore_to: CurrentAllocatorInUse)

Restore the current allocator in use.

fn coroutine_local_allocator(&self) -> Option<&Self::CoroutineLocalAllocator>

Obtain the current coroutine local allocator, if any.

fn thread_local_allocator(&self) -> Option<&Self::ThreadLocalAllocator>

Obtain the thread local allocator.

None if no thread local allocator has been initialized with initialize_thread_local_allocator().

fn global_allocator(&self) -> &Self::GlobalAllocator

Obtain the global allocator.

Loading content...

Provided methods

fn replace_current_allocator_in_use(
    &self,
    replacement: CurrentAllocatorInUse
) -> CurrentAllocatorInUse

Replace the current allocator in use.

fn callback_with_coroutine_local_allocator<R>(
    &self,
    callback: impl FnOnce() -> R
) -> R

Switch the current allocator in use to coroutine local and execute the callback; restore it after calling the callback unless a panic occurs.

fn callback_with_thread_local_allocator<R>(
    &self,
    callback: impl FnOnce() -> R
) -> R

Switch the current allocator in use to thread local and execute the callback; restore it after calling the callback unless a panic occurs.

fn callback_with_global_allocator<R>(&self, callback: impl FnOnce() -> R) -> R

Switch the current allocator in use to global and execute the callback; restore it after calling the callback unless a panic occurs.

fn callback_with_different_current_allocator<R>(
    &self,
    different: CurrentAllocatorInUse,
    callback: impl FnOnce() -> R
) -> R

Switch the current allocator in use and execute the callback; restore it after calling the callback unless a panic occurs.

fn coroutine_local_allocator_unchecked(&self) -> &Self::CoroutineLocalAllocator

Obtain the coroutine local allocator.

Panics if no coroutine local allocator has been assigned with replace_coroutine_local_allocator().

fn thread_local_allocator_unchecked(&self) -> &Self::ThreadLocalAllocator

Obtain the thread local allocator.

Panics if no thread local allocator has been initialized with initialize_thread_local_allocator().

Loading content...

Implementors

Loading content...