#[repr(C)]pub struct Arc<T: ?Sized> { /* private fields */ }
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
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 unsafe fn new_static<F>(alloc: F, data: T) -> Arc<T>where
F: FnOnce(Layout) -> *mut u8,
pub unsafe fn new_static<F>(alloc: F, data: T) -> Arc<T>where F: FnOnce(Layout) -> *mut u8,
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.
sourcepub fn with_raw_offset_arc<F, U>(&self, f: F) -> Uwhere
F: FnOnce(&RawOffsetArc<T>) -> U,
pub fn with_raw_offset_arc<F, U>(&self, f: F) -> Uwhere F: FnOnce(&RawOffsetArc<T>) -> U,
Temporarily converts |self| into a bonafide RawOffsetArc and exposes it to the provided callback. The refcount is not modified.
source§impl<T: ?Sized> Arc<T>
impl<T: ?Sized> Arc<T>
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.
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<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.
source§impl<H, T> Arc<HeaderSlice<HeaderWithLength<H>, [T]>>
impl<H, T> Arc<HeaderSlice<HeaderWithLength<H>, [T]>>
source§impl<T> Arc<T>
impl<T> Arc<T>
sourcepub fn into_raw_offset(a: Self) -> RawOffsetArc<T>
pub fn into_raw_offset(a: Self) -> RawOffsetArc<T>
Converts an Arc
into a RawOffsetArc
. This consumes the Arc
, so the refcount
is not modified.
sourcepub fn from_raw_offset(a: RawOffsetArc<T>) -> Self
pub fn from_raw_offset(a: RawOffsetArc<T>) -> Self
Converts a RawOffsetArc
into an Arc
. This consumes the RawOffsetArc
, so the refcount
is not modified.