pub struct OffsetArc<T> { /* private fields */ }
Expand description
An Arc
, except it holds a pointer to the T instead of to the
entire ArcInner.
An OffsetArc<T>
has the same layout and ABI as a non-null
const T*
in C, and may be used in FFI function signatures.
Arc<T> OffsetArc<T>
| |
v v
---------------------
| RefCount | T (data) | [ArcInner<T>]
---------------------
This means that this is a direct pointer to
its contained data (and can be read from by both C++ and Rust),
but we can also convert it to a “regular” Arc<T>
by removing the offset.
This is very useful if you have an Arc-containing struct shared between Rust and C++,
and wish for C++ to be able to read the data behind the Arc
without incurring
an FFI call overhead.
Implementations§
source§impl<T> OffsetArc<T>
impl<T> OffsetArc<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 make_mut(&mut self) -> &mut Twhere
T: Clone,
pub fn make_mut(&mut self) -> &mut Twhere
T: Clone,
If uniquely owned, provide a mutable reference Else create a copy, and mutate that
This is functionally the same thing as Arc::make_mut
sourcepub fn borrow_arc(&self) -> ArcBorrow<'_, T>
pub fn borrow_arc(&self) -> ArcBorrow<'_, T>
Produce a pointer to the data that can be converted back
to an Arc
Trait Implementations§
impl<T: Eq> Eq for OffsetArc<T>
impl<T: Sync + Send> Send for OffsetArc<T>
impl<T: Sync + Send> Sync for OffsetArc<T>
Auto Trait Implementations§
impl<T> Freeze for OffsetArc<T>
impl<T> RefUnwindSafe for OffsetArc<T>where
T: RefUnwindSafe,
impl<T> Unpin for OffsetArc<T>where
T: Unpin,
impl<T> UnwindSafe for OffsetArc<T>where
T: RefUnwindSafe + UnwindSafe,
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
)