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§
Required Methods§
Sourcefn clone(state_ptr: NonNull<Self::State>) -> NonNull<Self::State>
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.
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.