BlockRefDynamic

Trait BlockRefDynamic 

Source
pub unsafe trait BlockRefDynamic {
    type State;

    // Required methods
    fn clone(state_ptr: NonNull<Self::State>) -> NonNull<Self::State>;
    fn drop(state_ptr: NonNull<Self::State>);
}
Expand description

Implements the dynamic logic inside a BlockRef and can be used to create a BlockRefVTable.

This is the minimal that required to implement a BlockRef for a memory provider.

A typical high-efficiency implementation for a pooling memory provider will resemble something like an Arc<...>, with cloning and dropping adjusting the reference count and potentially returning the block to the pool.

§Safety

A BlockRef may move between threads and be accessed from any thread, while different clones of a BlockRef may be accessed concurrently from different threads.

The implementation must accordingly be thread-safe to the degree required to correctly operate under these conditions.

Required Associated Types§

Source

type State

The inner state passed from the BlockRef to the implementation of this trait with each function call.

Required Methods§

Source

fn clone(state_ptr: NonNull<Self::State>) -> NonNull<Self::State>

Will be called when a BlockRef is cloned, which means ownership of the block is to be shared with another co-owner.

The owners themselves coordinate who owns which part of the block and the BlockRef always represents the block as a whole.

§Returns

Returns a pointer to use for the dynamic implementation state of the new clone. The same state may be reused between clones, so the returned pointer may just be a pointer to the first function parameter received here.

The pointer must be valid for reads for the lifetime of the clone and there must never exist any exclusive references to it, as the caller will create shared references on demand.

Source

fn drop(state_ptr: NonNull<Self::State>)

Will be called when a BlockRef is dropped.

The caller will not access state after this call, so it is safe to deallocate the backing memory if the implementation itself no longer needs the state.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§