#[repr(transparent)]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
sourceimpl<T> OffsetArc<T>
impl<T> OffsetArc<T>
sourcepub fn with_arc<F, U>(&self, f: F) -> Uwhere
F: FnOnce(&Arc<T>) -> U,
pub fn with_arc<F, U>(&self, f: F) -> Uwhere
F: FnOnce(&Arc<T>) -> 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