Struct servo_arc::ThinArc

source ·
#[repr(C)]
pub struct ThinArc<H, T> { /* private fields */ }
Expand description

A “thin” Arc containing dynamically sized data

This is functionally equivalent to Arc<(H, [T])>

When you create an Arc containing a dynamically sized type like HeaderSlice<H, [T]>, the Arc is represented on the stack as a “fat pointer”, where the length of the slice is stored alongside the Arc’s pointer. In some situations you may wish to have a thin pointer instead, perhaps for FFI compatibility or space efficiency.

Note that we use [T; 0] in order to have the right alignment for T.

ThinArc solves this by storing the length in the allocation itself, via HeaderSliceWithLength.

Implementations§

source§

impl<H, T> ThinArc<H, T>

source

pub fn with_arc<F, U>(&self, f: F) -> Uwhere F: FnOnce(&Arc<HeaderSlice<HeaderWithLength<H>, [T]>>) -> U,

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

source

pub fn from_header_and_iter<I>(header: H, items: I) -> Selfwhere I: Iterator<Item = T> + ExactSizeIterator,

Creates a ThinArc for a HeaderSlice using the given header struct and iterator to generate the slice.

source

pub unsafe fn static_from_header_and_iter<F, I>( alloc: F, header: H, items: I ) -> Selfwhere F: FnOnce(Layout) -> *mut u8, I: Iterator<Item = T> + ExactSizeIterator,

Create a static ThinArc for a HeaderSlice using the given header struct and iterator to generate the slice, placing it in the allocation provided by the specified alloc function.

alloc must return a pointer into a static allocation suitable for storing data with the Layout passed into it. The pointer returned by alloc will not be freed.

source

pub fn ptr(&self) -> *const c_void

Returns the address on the heap of the ThinArc itself – not the T within it – for memory reporting, and bindings.

source

pub fn heap_ptr(&self) -> *const c_void

If this is a static ThinArc, this returns null.

Trait Implementations§

source§

impl<H, T> Clone for ThinArc<H, 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<H: Debug, T: Debug> Debug for ThinArc<H, T>

source§

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

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

impl<H, T> Deref for ThinArc<H, T>

§

type Target = HeaderSlice<HeaderWithLength<H>, [T]>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<H, T> Drop for ThinArc<H, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<H: PartialEq, T: PartialEq> PartialEq<ThinArc<H, T>> for ThinArc<H, T>

source§

fn eq(&self, other: &ThinArc<H, 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<H: Eq, T: Eq> Eq for ThinArc<H, T>

source§

impl<H: Sync + Send, T: Sync + Send> Send for ThinArc<H, T>

source§

impl<H: Sync + Send, T: Sync + Send> Sync for ThinArc<H, T>

Auto Trait Implementations§

§

impl<H, T> RefUnwindSafe for ThinArc<H, T>where H: RefUnwindSafe, T: RefUnwindSafe,

§

impl<H, T> Unpin for ThinArc<H, T>where H: Unpin, T: Unpin,

§

impl<H, T> UnwindSafe for ThinArc<H, T>where H: UnwindSafe + RefUnwindSafe, T: UnwindSafe + 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.