servo_arc

Struct 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) -> U
where 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) -> Self
where 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, ) -> Self
where 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>

Source§

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 for ThinArc<H, T>

Source§

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

§

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

§

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

§

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

Blanket Implementations§

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 u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 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 = 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.