Struct servo_arc::ArcBorrow

source ·
pub struct ArcBorrow<'a, T: 'a>(pub(crate) &'a T);
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.

ArcBorrow lets us deal with borrows of known-refcounted objects without needing to worry about where the Arc<T> is.

Tuple Fields§

§0: &'a T

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_ref(r: &'a T) -> Self

For constructing from a reference known to be Arc-backed, e.g. if we obtain such a reference over FFI

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 with_arc<F, U>(&self, f: F) -> Uwhere F: FnOnce(&Arc<T>) -> U, T: 'static,

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<'a, T: Debug + '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>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

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

source§

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

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

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

This method 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 + 'a> Eq for ArcBorrow<'a, T>

source§

impl<'a, T: 'a> StructuralEq for ArcBorrow<'a, T>

source§

impl<'a, T: 'a> StructuralPartialEq for ArcBorrow<'a, T>

Auto Trait Implementations§

§

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

§

impl<'a, T> Send for ArcBorrow<'a, T>where T: Sync,

§

impl<'a, T> Sync for ArcBorrow<'a, T>where T: Sync,

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.