Struct to_shmem::SharedMemoryBuilder

source ·
pub struct SharedMemoryBuilder {
    pub(crate) buffer: *mut u8,
    pub(crate) capacity: usize,
    pub(crate) index: usize,
    pub(crate) shared_values: HashSet<*const c_void>,
}
Expand description

A builder object that transforms and copies values into a fixed size buffer.

Fields§

§buffer: *mut u8

The buffer into which values will be copied.

§capacity: usize

The size of the buffer.

§index: usize

The current position in the buffer, where the next value will be written at.

§shared_values: HashSet<*const c_void>

Pointers to every shareable value that we store in the shared memory buffer. We use this to assert against encountering the same value twice, e.g. through another Arc reference, so that we don’t inadvertently store duplicate copies of values.

Implementations§

source§

impl SharedMemoryBuilder

source

pub unsafe fn new(buffer: *mut u8, capacity: usize) -> SharedMemoryBuilder

Creates a new SharedMemoryBuilder using the specified buffer.

source

pub fn len(&self) -> usize

Returns the number of bytes currently used in the buffer.

source

pub fn write<T: ToShmem>(&mut self, value: &T) -> Result<*mut T, String>

Writes a value into the shared memory buffer and returns a pointer to it in the buffer.

The value is cloned and converted into a form suitable for placing into a shared memory buffer by calling ToShmem::to_shmem on it.

Panics if there is insufficient space in the buffer.

source

pub fn alloc_value<T>(&mut self) -> *mut T

Reserves space in the shared memory buffer to fit a value of type T, and returns a pointer to that reserved space.

Panics if there is insufficient space in the buffer.

source

pub fn alloc_array<T>(&mut self, len: usize) -> *mut T

Reserves space in the shared memory buffer to fit an array of values of type T, and returns a pointer to that reserved space.

Panics if there is insufficient space in the buffer.

source

pub fn alloc<T>(&mut self, layout: Layout) -> *mut T

Reserves space in the shared memory buffer that conforms to the specified layout, and returns a pointer to that reserved space.

Panics if there is insufficient space in the buffer.

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