#[repr(C)]pub struct ThinArc<H, T> {
pub(crate) ptr: NonNull<ArcInner<HeaderSlice<HeaderWithLength<H>, [T; 0]>>>,
pub(crate) phantom: PhantomData<(H, T)>,
}
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
.
Fields§
§ptr: NonNull<ArcInner<HeaderSlice<HeaderWithLength<H>, [T; 0]>>>
§phantom: PhantomData<(H, T)>
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 unsafe fn static_from_header_and_iter<F, I>(
alloc: F,
header: H,
items: I
) -> Selfwhere
F: FnOnce(Layout) -> *mut u8,
I: Iterator<Item = T> + ExactSizeIterator,
pub unsafe fn static_from_header_and_iter<F, I>(
alloc: F,
header: H,
items: I
) -> Selfwhere
F: FnOnce(Layout) -> *mut u8,
I: Iterator<Item = T> + ExactSizeIterator,
Create a static ThinArc
for a HeaderSlice using the given header
struct and iterator to generate the slice, placing it in the allocation
provided by the specified alloc
function.
alloc
must return a pointer into a static allocation suitable for
storing data with the Layout
passed into it. The pointer returned by
alloc
will not be freed.