triomphe

Struct ArcBorrow

source
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> ArcBorrow<'a, T>

source

pub fn clone_arc(&self) -> Arc<T>

Clone this as an Arc<T>. This bumps the refcount.

source

pub 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 T must have come from a Triomphe Arc, UniqueArc, or ArcBorrow.
  • The pointer to T must have full provenance over the Arc, UniqueArc, or ArcBorrow, in particular it must not have been derived from a &T reference, as references immediately loose all provenance over the adjacent reference counts. As of this writing, of the 3 types, only Trimphe’s Arc offers a direct API for obtaining such a pointer: Arc::as_ptr.
source

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

source

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.

source

pub fn with_arc<F, U>(&self, f: F) -> U
where F: FnOnce(&Arc<T>) -> U,

Temporarily converts |self| into a bonafide Arc and exposes it to the provided callback. The refcount is not modified.

source

pub fn get(&self) -> &'a T

Similar to deref, but uses the lifetime |a| rather than the lifetime of self, which is incompatible with the signature of the Deref trait.

Trait Implementations§

source§

impl<'a, T> Clone for ArcBorrow<'a, T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'lt, T: 'lt, U: ?Sized + 'lt> CoerciblePtr<U> for ArcBorrow<'lt, T>

source§

type Pointee = T

The type we point to. This influences which kinds of unsizing are possible.
source§

type Output = ArcBorrow<'lt, U>

The output type when unsizing the pointee to U.
source§

fn as_sized_ptr(&mut self) -> *mut T

Get the raw inner pointer.
source§

unsafe fn replace_ptr(self, new: *mut U) -> ArcBorrow<'lt, U>

Replace the container inner pointer with an unsized version. Read more
source§

impl<'a, T: Debug + ?Sized + 'a> Debug for ArcBorrow<'a, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, T> Deref for ArcBorrow<'a, T>

source§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<'a, T: PartialEq + ?Sized + 'a> PartialEq for ArcBorrow<'a, T>

source§

fn eq(&self, other: &ArcBorrow<'a, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, T> Copy for ArcBorrow<'a, T>

source§

impl<'a, T: Eq + ?Sized + 'a> Eq for ArcBorrow<'a, T>

source§

impl<'a, T: ?Sized + Sync + Send> Send for ArcBorrow<'a, T>

source§

impl<'a, T: ?Sized + 'a> StructuralPartialEq for ArcBorrow<'a, T>

source§

impl<'a, T: ?Sized + Sync + Send> Sync for ArcBorrow<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for ArcBorrow<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for ArcBorrow<'a, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T> Unpin for ArcBorrow<'a, T>
where T: ?Sized,

§

impl<'a, T> UnwindSafe for ArcBorrow<'a, T>
where T: RefUnwindSafe + ?Sized,

Blanket Implementations§

source§

impl<T, A, P> Access<T> for P
where A: Access<T> + ?Sized, P: Deref<Target = A>,

source§

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more
source§

fn load(&self) -> <P as Access<T>>::Guard

The loading method. Read more
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T, U> CoerceUnsize<U> for T
where T: CoerciblePtr<U>, U: ?Sized,

source§

fn unsize<F>(self, with: Coercion<Self::Pointee, U, F>) -> Self::Output
where F: FnOnce(*const Self::Pointee) -> *const U,

Convert a pointer, as if with unsize coercion. Read more
source§

impl<T, A> DynAccess<T> for A
where A: Access<T>, <A as Access<T>>::Guard: 'static,

source§

fn load(&self) -> DynGuard<T>

The equivalent of Access::load.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.