#[repr(C)]pub struct Arc<T, Alloc: IAlloc = DefaultAllocator> { /* private fields */ }Expand description
alloc::sync::Arc, but ABI-stable.
Implementations§
Source§impl<T, Alloc: IAlloc> Arc<T, Alloc>
impl<T, Alloc: IAlloc> Arc<T, Alloc>
Sourcepub const fn has_optimal_layout() -> bool
pub const fn has_optimal_layout() -> bool
Returns true if the layout for Arc is smaller or equal to that Rust would have generated for it.
Source§impl<T> Arc<T>
impl<T> Arc<T>
Sourcepub unsafe fn make<F: for<'a> FnOnce(&'a mut MaybeUninit<T>) -> Result<&'a mut T, ()>>(
constructor: F,
) -> Result<Self, Arc<MaybeUninit<T>>>
pub unsafe fn make<F: for<'a> FnOnce(&'a mut MaybeUninit<T>) -> Result<&'a mut T, ()>>( constructor: F, ) -> Result<Self, Arc<MaybeUninit<T>>>
Attempts to allocate Self, initializing it with constructor.
Note that the allocation may or may not be zeroed.
If the allocation fails, the constructor will not be run.
§Safety
constructor MUST return Err(()) if it failed to initialize the passed argument.
§Errors
Returns the uninitialized allocation if the constructor declares a failure.
§Panics
If the allocator fails to provide an appropriate allocation.
Source§impl<T, Alloc: IAlloc> Arc<T, Alloc>
impl<T, Alloc: IAlloc> Arc<T, Alloc>
Sourcepub unsafe fn try_make_in<F: for<'a> FnOnce(&'a mut MaybeUninit<T>) -> Result<&'a mut T, ()>>(
constructor: F,
alloc: Alloc,
) -> Result<Self, Result<Arc<MaybeUninit<T>, Alloc>, (F, Alloc)>>
pub unsafe fn try_make_in<F: for<'a> FnOnce(&'a mut MaybeUninit<T>) -> Result<&'a mut T, ()>>( constructor: F, alloc: Alloc, ) -> Result<Self, Result<Arc<MaybeUninit<T>, Alloc>, (F, Alloc)>>
Attempts to allocate Self, initializing it with constructor.
Note that the allocation may or may not be zeroed.
If the constructor panics, the allocated memory will be leaked.
§Errors
- Returns the
constructorand the allocator in case of allocation failure. - Returns the uninitialized allocated memory if
constructorfails.
§Safety
constructor MUST return Err(()) if it failed to initialize the passed argument.
§Notes
Note that the allocation may or may not be zeroed.
Sourcepub fn try_new_in(value: T, alloc: Alloc) -> Result<Self, (T, Alloc)>
pub fn try_new_in(value: T, alloc: Alloc) -> Result<Self, (T, Alloc)>
Sourcepub unsafe fn make_in<F: for<'a> FnOnce(&'a mut MaybeUninit<T>) -> Result<&'a mut T, ()>>(
constructor: F,
alloc: Alloc,
) -> Result<Self, Arc<MaybeUninit<T>, Alloc>>
pub unsafe fn make_in<F: for<'a> FnOnce(&'a mut MaybeUninit<T>) -> Result<&'a mut T, ()>>( constructor: F, alloc: Alloc, ) -> Result<Self, Arc<MaybeUninit<T>, Alloc>>
Attempts to allocate Self, initializing it with constructor.
Note that the allocation may or may not be zeroed.
§Errors
Returns the uninitialized allocated memory if constructor fails.
§Safety
constructor MUST return Err(()) if it failed to initialize the passed argument.
§Panics
If the allocator fails to provide an appropriate allocation.
Sourcepub const fn into_raw(this: Self) -> AllocPtr<T, Alloc>
pub const fn into_raw(this: Self) -> AllocPtr<T, Alloc>
Returns the pointer to the inner raw allocation, leaking this.
Note that the pointer may be dangling if T is zero-sized.
Sourcepub const unsafe fn from_raw(this: AllocPtr<T, Alloc>) -> Self
pub const unsafe fn from_raw(this: AllocPtr<T, Alloc>) -> Self
Constructs Self from a raw allocation.
§Safety
this MUST not be dangling, and have been obtained through Self::into_raw.
Sourcepub fn get_mut(this: &mut Self) -> Option<&mut T>
pub fn get_mut(this: &mut Self) -> Option<&mut T>
Provides a mutable reference to the internals if the strong and weak counts are both 1.
Sourcepub const unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T
pub const unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T
Provides a mutable reference to the internals without checking.
§Safety
If used carelessly, this can cause mutable references and immutable references to the same value to appear, causing undefined behaviour.
Sourcepub fn strong_count(this: &Self) -> usize
pub fn strong_count(this: &Self) -> usize
Returns the strong count.
Sourcepub unsafe fn increment_strong_count(this: *const T) -> usize
pub unsafe fn increment_strong_count(this: *const T) -> usize
Sourcepub fn weak_count(this: &Self) -> usize
pub fn weak_count(this: &Self) -> usize
Returns the weak count. Note that all Arcs to a same value share a Weak, so the weak count can never be 0.
Sourcepub fn increment_weak_count(this: &Self) -> usize
pub fn increment_weak_count(this: &Self) -> usize
Increments the weak count, returning its previous value.
Sourcepub fn make_mut(&mut self) -> &mut T
pub fn make_mut(&mut self) -> &mut T
Returns a mutable reference to this Arc’s value, cloning that value into a new Arc if Self::get_mut would have failed.
Sourcepub fn make_mut_and_get_alloc(&mut self) -> (&mut T, &Alloc)
pub fn make_mut_and_get_alloc(&mut self) -> (&mut T, &Alloc)
Returns a mutable reference to this Arc’s value, cloning that value into a new Arc if Self::get_mut would have failed.
Sourcepub fn is_unique(this: &Self) -> bool
pub fn is_unique(this: &Self) -> bool
Whether or not this is the sole owner of its data, including weak owners.
Sourcepub fn try_into_inner(this: Self) -> Result<T, Self>
pub fn try_into_inner(this: Self) -> Result<T, Self>
Attempts the value from the allocation, freeing said allocation.
§Errors
Returns this if it’s not the sole owner of its value.
Trait Implementations§
Source§impl<T, Alloc: IAlloc> IPtrOwned for Arc<T, Alloc>
impl<T, Alloc: IAlloc> IPtrOwned for Arc<T, Alloc>
Source§fn drop(
this: &mut ManuallyDrop<Self>,
drop: unsafe extern "C" fn(AnonymRefMut<'_>),
)
fn drop( this: &mut ManuallyDrop<Self>, drop: unsafe extern "C" fn(AnonymRefMut<'_>), )
Drop::drop when the dynptr is dropped.Source§impl<T, Alloc: IAlloc> IPtrTryAsMut for Arc<T, Alloc>
impl<T, Alloc: IAlloc> IPtrTryAsMut for Arc<T, Alloc>
Source§unsafe fn try_as_mut(&mut self) -> Option<AnonymRefMut<'_>>
unsafe fn try_as_mut(&mut self) -> Option<AnonymRefMut<'_>>
Source§impl<T, Alloc: IAlloc> IStable for Arc<T, Alloc>
impl<T, Alloc: IAlloc> IStable for Arc<T, Alloc>
Source§const REPORT: &'static TypeReport
const REPORT: &'static TypeReport
Source§const ID: u64
const ID: u64
crate::report::gen_id, but can be manually set.Source§type ForbiddenValues = <Struct<AllocPtr<T, Alloc>> as IStable>::ForbiddenValues
type ForbiddenValues = <Struct<AllocPtr<T, Alloc>> as IStable>::ForbiddenValues
Source§type UnusedBits = <Struct<AllocPtr<T, Alloc>> as IStable>::UnusedBits
type UnusedBits = <Struct<AllocPtr<T, Alloc>> as IStable>::UnusedBits
Source§type Size = <Struct<AllocPtr<T, Alloc>> as IStable>::Size
type Size = <Struct<AllocPtr<T, Alloc>> as IStable>::Size
Source§type Align = <Struct<AllocPtr<T, Alloc>> as IStable>::Align
type Align = <Struct<AllocPtr<T, Alloc>> as IStable>::Align
Source§type HasExactlyOneNiche = <Struct<AllocPtr<T, Alloc>> as IStable>::HasExactlyOneNiche
type HasExactlyOneNiche = <Struct<AllocPtr<T, Alloc>> as IStable>::HasExactlyOneNiche
core::option::Options are stable: Read more