pub struct ArcBorrow<'a, T: ?Sized + 'a>(/* private fields */);Expand description
A “borrowed Arc”. This is a pointer to
a T that is known to have been allocated within an
Arc.
This is equivalent in guarantees to &Arc<T>, however it is
a bit more flexible. To obtain an &Arc<T> you must have
an Arc<T> instance somewhere pinned down until we’re done with it.
It’s also a direct pointer to T, so using this involves less pointer-chasing
However, C++ code may hand us refcounted things as pointers to T directly,
so we have to conjure up a temporary Arc on the stack each time. The
same happens for when the object is managed by a OffsetArc.
ArcBorrow lets us deal with borrows of known-refcounted objects
without needing to worry about where the Arc<T> is.
Implementations§
Source§impl<'a, T: ?Sized> ArcBorrow<'a, T>
impl<'a, T: ?Sized> ArcBorrow<'a, T>
Sourcepub const fn to_raw(this: &Self) -> *const T
pub const fn to_raw(this: &Self) -> *const T
Returns the raw pointer to T.
This pointer retains full provenance over the entire ArcInner allocation,
and thus can be safely passed to Arc::from_raw.
Sourcepub const unsafe fn from_ptr(ptr: *const T) -> Self
pub const unsafe fn from_ptr(ptr: *const T) -> Self
For constructing from a pointer known to be Arc-backed, e.g. if we obtain such a pointer over FFI
§Safety
- The pointer to
Tmust have come from a TriompheArc,UniqueArc, orArcBorrowthat remains live (strong count >= 1) for the entire lifetime'a, andTmust not be mutably accessed for the duration of'a. - The pointer to
Tmust have full provenance over theArc,UniqueArc, orArcBorrow, in particular it must not have been derived from a&Treference, as references immediately lose all provenance over the adjacent reference counts. Triomphe’sArcandArcBorrowoffer direct APIs for obtaining such a pointer:Arc::as_ptr,Arc::into_raw, andArcBorrow::to_raw.
Sourcepub fn ptr_eq(this: &Self, other: &Self) -> bool
pub fn ptr_eq(this: &Self, other: &Self) -> bool
Compare two ArcBorrows via pointer equality. Will only return
true if they come from the same allocation
Sourcepub fn strong_count(this: &Self) -> usize
pub fn strong_count(this: &Self) -> usize
The reference count of the underlying 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§
Source§impl<'lt, T: 'lt, U: ?Sized + 'lt> CoerciblePtr<U> for ArcBorrow<'lt, T>
Available on crate feature unsize only.
impl<'lt, T: 'lt, U: ?Sized + 'lt> CoerciblePtr<U> for ArcBorrow<'lt, T>
unsize only.Source§fn as_sized_ptr(&mut self) -> *mut T
fn as_sized_ptr(&mut self) -> *mut T
impl<'a, T: ?Sized> Copy for ArcBorrow<'a, T>
impl<'a, T: Eq + ?Sized + 'a> Eq for ArcBorrow<'a, T>
impl<'a, T: ?Sized + Sync + Send> Send for ArcBorrow<'a, T>
impl<'a, T: PartialEq + ?Sized + 'a> StructuralPartialEq for ArcBorrow<'a, T>
impl<'a, T: ?Sized + Sync + Send> Sync for ArcBorrow<'a, T>
impl<'a, T: RefUnwindSafe + ?Sized> UnwindSafe for ArcBorrow<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for ArcBorrow<'a, T>
impl<'a, T> RefUnwindSafe for ArcBorrow<'a, T>
impl<'a, T> Unpin for ArcBorrow<'a, T>
impl<'a, T> UnsafeUnpin for ArcBorrow<'a, 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§impl<T, U> CoerceUnsize<U> for Twhere
T: CoerciblePtr<U>,
U: ?Sized,
impl<T, U> CoerceUnsize<U> for Twhere
T: CoerciblePtr<U>,
U: ?Sized,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.