BlockRef

Struct BlockRef 

Source
pub struct BlockRef { /* private fields */ }
Expand description

A reference to a block of memory capacity owned by a memory provider and leased to user code.

While a memory provider only leases each block to one caller at a time, this caller may further share and subdivide the block between multiple co-owners. These co-owners will coordinate the read/write permissions over different slices of the block via their own logic, with the BlockRef only used to represent the block as a whole, each co-owner having a cloned BlockRef to the same block.

§Implementation design

Each memory provider implements its own accounting logic for tracking the memory blocks it provides. This takes the form of a “manual” dynamic dispatch implementation via a function table and data pointer passed to new().

You can think of BlockRef as an Arc<RealBlock>, except we are intentionally obscuring the RealBlock from the API surface to allow all code upstream of BlockRef to be ignorant of the real type of the block.

The assumption is that an efficient memory provider will allocate its data objects in a pool, so if the BlockRef itself is held on the stack, there are no heap allocations necessary to operate on memory blocks. This would be infeasible to achieve with trait objects, which are unsized and have significant limitations on how they can be used. This is why we use the manual dynamic dispatch mechanism instead of using Rust’s trait system.

Implementations§

Source§

impl BlockRef

Source

pub const unsafe fn new<T: BlockRefDynamic>( state: NonNull<T::State>, vtable: &'static BlockRefVTable<T>, ) -> Self

Creates a new block reference using the provided dynamic implementation state and matching function table.

§Safety

state must remain valid for reads and writes until BlockRefDynamic::drop is called via vtable.

Source

pub fn meta(&self) -> Option<&dyn Any>

Memory provider specific metadata describing the block.

Trait Implementations§

Source§

impl Clone for BlockRef

Source§

fn clone(&self) -> Self

Returns a duplicate 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 BlockRef

Source§

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

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

impl Drop for BlockRef

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for BlockRef

Source§

impl Sync for BlockRef

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.