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
Sourcepub fn strong_count(this: &Self) -> usize
pub fn strong_count(this: &Self) -> usize
The reference count of this Arc.
The number does not include borrowed pointers,
or temporary Arc pointers created with functions like
ArcBorrow::with_arc.
The function is called strong_count to mirror std::sync::Arc::strong_count,
however triomphe::Arc does not support weak references.
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,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes