#[repr(transparent)]pub struct ThinArc<H, T> { /* private fields */ }
Expand description
A “thin” Arc
containing dynamically sized data
This is functionally equivalent to Arc<(H, [T])>
When you create an Arc
containing a dynamically sized type
like HeaderSlice<H, [T]>
, the Arc
is represented on the stack
as a “fat pointer”, where the length of the slice is stored
alongside the Arc
’s pointer. In some situations you may wish to
have a thin pointer instead, perhaps for FFI compatibility
or space efficiency.
Note that we use [T; 0]
in order to have the right alignment for T
.
ThinArc
solves this by storing the length in the allocation itself,
via HeaderSliceWithLength
.
Implementations
sourceimpl<H, T> ThinArc<H, T>
impl<H, T> ThinArc<H, T>
sourcepub fn with_arc<F, U>(&self, f: F) -> Uwhere
F: FnOnce(&Arc<HeaderSlice<HeaderWithLength<H>, [T]>>) -> U,
pub fn with_arc<F, U>(&self, f: F) -> Uwhere
F: FnOnce(&Arc<HeaderSlice<HeaderWithLength<H>, [T]>>) -> U,
Temporarily converts |self| into a bonafide Arc and exposes it to the provided callback. The refcount is not modified.
sourcepub fn from_header_and_iter<I>(header: H, items: I) -> Selfwhere
I: Iterator<Item = T> + ExactSizeIterator,
pub fn from_header_and_iter<I>(header: H, items: I) -> Selfwhere
I: Iterator<Item = T> + ExactSizeIterator,
Creates a ThinArc
for a HeaderSlice using the given header struct and
iterator to generate the slice.
sourcepub fn from_header_and_slice(header: H, items: &[T]) -> Selfwhere
T: Copy,
pub fn from_header_and_slice(header: H, items: &[T]) -> Selfwhere
T: Copy,
Creates a ThinArc
for a HeaderSlice using the given header struct and
a slice to copy.
sourcepub fn ptr(&self) -> *const c_void
pub fn ptr(&self) -> *const c_void
Returns the address on the heap of the ThinArc itself – not the T within it – for memory reporting.
sourcepub fn heap_ptr(&self) -> *const c_void
pub fn heap_ptr(&self) -> *const c_void
Returns the address on the heap of the Arc itself – not the T within it – for memory reporting.
sourcepub unsafe fn from_raw(ptr: *const c_void) -> Self
pub unsafe fn from_raw(ptr: *const c_void) -> Self
Safety
Constructs an ThinArc from a raw pointer.
The raw pointer must have been previously returned by a call to ThinArc::into_raw.
The user of from_raw has to make sure a specific value of T is only dropped once.
This function is unsafe because improper use may lead to memory unsafety, even if the returned ThinArc is never accessed.