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§
source§impl<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.
Trait Implementations§
source§impl<H, T> Deref for ThinArc<H, T>
impl<H, T> Deref for ThinArc<H, T>
§type Target = HeaderSlice<HeaderWithLength<H>, [T]>
type Target = HeaderSlice<HeaderWithLength<H>, [T]>
source§impl<H: Ord, T: Ord> Ord for ThinArc<H, T>
impl<H: Ord, T: Ord> Ord for ThinArc<H, T>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<H: PartialEq, T: PartialEq> PartialEq for ThinArc<H, T>
impl<H: PartialEq, T: PartialEq> PartialEq for ThinArc<H, T>
source§impl<H: PartialOrd, T: PartialOrd> PartialOrd for ThinArc<H, T>
impl<H: PartialOrd, T: PartialOrd> PartialOrd for ThinArc<H, T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more