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) -> U
pub fn with_arc<F, U>(&self, f: F) -> 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>
source§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: PartialOrd, T: PartialOrd> PartialOrd for ThinArc<H, T>
impl<H: PartialOrd, T: PartialOrd> PartialOrd for ThinArc<H, T>
impl<H: Eq, T: Eq> Eq for ThinArc<H, T>
impl<H: Sync + Send, T: Sync + Send> Send for ThinArc<H, T>
impl<H: Sync + Send, T: Sync + Send> Sync for ThinArc<H, T>
Auto Trait Implementations§
impl<H, T> Freeze for ThinArc<H, T>
impl<H, T> RefUnwindSafe for ThinArc<H, T>where
H: RefUnwindSafe,
T: RefUnwindSafe,
impl<H, T> Unpin for ThinArc<H, T>
impl<H, T> UnwindSafe for ThinArc<H, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)