#[repr(C)]pub struct Arc<T: ?Sized> {
pub(crate) p: NonNull<ArcInner<T>>,
pub(crate) phantom: PhantomData<T>,
}Expand description
An atomically reference counted shared pointer
See the documentation for Arc in the standard library. Unlike the
standard library Arc, this Arc does not support weak reference counting.
See the discussion in https://github.com/rust-lang/rust/pull/60594 for the usage of PhantomData.
cbindgen:derive-eq=false cbindgen:derive-neq=false
Fields§
§p: NonNull<ArcInner<T>>§phantom: PhantomData<T>Implementations§
Source§impl<T> Arc<T>
impl<T> Arc<T>
Sourcepub fn new_leaked(data: T) -> Self
pub fn new_leaked(data: T) -> Self
Construct an intentionally-leaked arc.
Sourcepub fn into_raw(this: Self) -> *const T
pub fn into_raw(this: Self) -> *const T
Convert the Arc
Note: This returns a pointer to the data T, which is offset in the allocation.
Sourcepub unsafe fn from_raw(ptr: *const T) -> Self
pub unsafe fn from_raw(ptr: *const T) -> Self
Reconstruct the Arc
Note: This raw pointer will be offset in the allocation and must be preceded by the atomic count.
Sourcepub unsafe fn from_raw_addrefed(ptr: *const T) -> Self
pub unsafe fn from_raw_addrefed(ptr: *const T) -> Self
Like from_raw, but returns an addrefed arc instead.
Sourcepub unsafe fn new_static<F>(alloc: F, data: T) -> Arc<T>
pub unsafe fn new_static<F>(alloc: F, data: T) -> Arc<T>
Create a new static Arcalloc
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.
Sourcepub fn borrow_arc<'a>(&'a self) -> ArcBorrow<'a, T>
pub fn borrow_arc<'a>(&'a self) -> ArcBorrow<'a, T>
Produce a pointer to the data that can be converted back
to an Arc. This is basically an &Arc<T>, without the extra indirection.
It has the benefits of an &T but also knows about the underlying refcount
and can be converted into more Arc<T>s if necessary.
Source§impl<T: ?Sized> Arc<T>
impl<T: ?Sized> Arc<T>
pub(crate) fn inner(&self) -> &ArcInner<T>
pub(crate) fn record_drop(&self)
Sourcepub fn mark_as_intentionally_leaked(&self)
pub fn mark_as_intentionally_leaked(&self)
Marks this Arc as intentionally leaked for the purposes of refcount
logging.
It’s a logic error to call this more than once, but it’s not unsafe, as it’d just report negative leaks.
pub(crate) unsafe fn drop_slow(&mut self)
Sourcepub fn ptr_eq(this: &Self, other: &Self) -> bool
pub fn ptr_eq(this: &Self, other: &Self) -> bool
Test pointer equality between the two Arcs, i.e. they must be the same allocation
pub(crate) fn ptr(&self) -> *mut ArcInner<T>
Source§impl<T: Clone> Arc<T>
impl<T: Clone> Arc<T>
Sourcepub fn make_mut(this: &mut Self) -> &mut T
pub fn make_mut(this: &mut Self) -> &mut T
Makes a mutable reference to the Arc, cloning if necessary
This is functionally equivalent to Arc::make_mut from the standard library.
If this Arc is uniquely owned, make_mut() will provide a mutable
reference to the contents. If not, make_mut() will create a new Arc
with a copy of the contents, update this to point to it, and provide
a mutable reference to its contents.
This is useful for implementing copy-on-write schemes where you wish to
avoid copying things if your Arc is not shared.
Source§impl<T: ?Sized> Arc<T>
impl<T: ?Sized> Arc<T>
Source§impl<H, T> Arc<HeaderSlice<H, T>>
impl<H, T> Arc<HeaderSlice<H, T>>
Sourcepub fn from_header_and_iter_alloc<F, I>(
alloc: F,
header: H,
items: I,
num_items: usize,
is_static: bool,
) -> Self
pub fn from_header_and_iter_alloc<F, I>( alloc: F, header: H, items: I, num_items: usize, is_static: bool, ) -> Self
Creates an Arc for a HeaderSlice using the given header struct and iterator to generate the slice.
is_static indicates whether to create a static Arc.
alloc is used to get a pointer to the memory into which the
dynamically sized ArcInner<HeaderSlice<H, T>> value will be
written. If is_static is true, then alloc must return a
pointer into some static memory allocation. If it is false,
then alloc must return an allocation that can be dellocated
by calling Box::from_raw::<ArcInner<HeaderSlice<H, T>>> on it.
Sourcepub fn from_header_and_iter_with_size<I>(
header: H,
items: I,
num_items: usize,
) -> Selfwhere
I: Iterator<Item = T>,
pub fn from_header_and_iter_with_size<I>(
header: H,
items: I,
num_items: usize,
) -> Selfwhere
I: Iterator<Item = T>,
Creates an Arc for a HeaderSlice using the given header struct and iterator to generate the slice. Panics if num_items doesn’t match the number of items.
Sourcepub fn from_header_and_iter<I>(header: H, items: I) -> Selfwhere
I: Iterator<Item = T> + ExactSizeIterator,
pub fn from_header_and_iter<I>(header: H, items: I) -> Selfwhere
I: Iterator<Item = T> + ExactSizeIterator,
Creates an Arc for a HeaderSlice using the given header struct and iterator to generate the slice. The resulting Arc will be fat.