Skip to main content

ArcBorrow

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: ?Sized> ArcBorrow<'a, T>

Source

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

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

Source

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.

Source

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 T must have come from a Triomphe Arc, UniqueArc, or ArcBorrow that remains live (strong count >= 1) for the entire lifetime 'a, and T must not be mutably accessed for the duration of 'a.
  • 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 lose all provenance over the adjacent reference counts. Triomphe’s Arc and ArcBorrow offer direct APIs for obtaining such a pointer: Arc::as_ptr, Arc::into_raw, and ArcBorrow::to_raw.
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 const 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: ?Sized> Clone for ArcBorrow<'a, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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>

Available on crate feature unsize only.
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: ?Sized> Copy for ArcBorrow<'a, T>

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: ?Sized> 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: Eq + ?Sized + 'a> Eq for ArcBorrow<'a, T>

Source§

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

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Source§

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

Source§

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, 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.