Lines Matching full:arc

5 //! A wrapper around `Arc` for linked lists.
10 use crate::sync::{Arc, ArcBorrow, UniqueArc};
58 /// Attempts to convert an `Arc<Self>` into an `ListArc<Self>`. Returns `true` if the
132 /// A wrapper around [`Arc`] that's guaranteed unique for the given id.
143 /// creation of new `ListArc` references from an [`Arc`] reference. Whatever strategy is used, the
153 /// While this `ListArc` is unique for the given id, there still might exist normal `Arc`
168 arc: Arc<T>,
182 // what we do for `Arc`.
223 let arc = Arc::from(unique);
224 // SAFETY: We just called `on_create_list_arc_from_unique` on an arc without a `ListArc`,
226 unsafe { Self::transmute_from_arc(arc) }
262 let arc1 = Arc::from(unique);
263 let arc2 = Arc::clone(&arc1);
265 // SAFETY: We just called `on_create_list_arc_from_unique` on an arc without a `ListArc`
278 pub fn try_from_arc(arc: Arc<T>) -> Result<Self, Arc<T>>
282 if arc.try_new_list_arc() {
285 Ok(unsafe { Self::transmute_from_arc(arc) })
287 Err(arc)
294 pub fn try_from_arc_borrow(arc: ArcBorrow<'_, T>) -> Option<Self>
298 if arc.try_new_list_arc() {
301 Some(unsafe { Self::transmute_from_arc(Arc::from(arc)) })
309 /// If it's not possible to create a new `ListArc`, then the `Arc` is dropped. This will never
311 pub fn try_from_arc_or_drop(arc: Arc<T>) -> Option<Self>
315 match Self::try_from_arc(arc) {
317 Err(arc) => Arc::into_unique_or_drop(arc).map(Self::from),
321 /// Transmutes an [`Arc`] into a `ListArc` without updating the tracking inside `T`.
328 unsafe fn transmute_from_arc(arc: Arc<T>) -> Self {
330 Self { arc }
333 /// Transmutes a `ListArc` into an [`Arc`] without updating the tracking inside `T`.
338 fn transmute_to_arc(self) -> Arc<T> {
347 /// The returned pointer is indistinguishable from pointers returned by [`Arc::into_raw`]. The
351 Arc::into_raw(Self::transmute_to_arc(self))
358 /// * `ptr` must satisfy the safety requirements of [`Arc::from_raw`].
363 // SAFETY: The pointer satisfies the safety requirements for `Arc::from_raw`.
364 let arc = unsafe { Arc::from_raw(ptr) };
367 unsafe { Self::transmute_from_arc(arc) }
370 /// Converts the `ListArc` into an [`Arc`].
372 pub fn into_arc(self) -> Arc<T> {
373 let arc = Self::transmute_to_arc(self);
375 unsafe { T::on_drop_list_arc(&arc) };
376 arc
379 /// Clone a `ListArc` into an [`Arc`].
381 pub fn clone_arc(&self) -> Arc<T> {
382 self.arc.clone()
385 /// Returns a reference to an [`Arc`] from the given [`ListArc`].
387 /// This is useful when the argument of a function call is an [`&Arc`] (e.g., in a method
390 /// [`&Arc`]: Arc
392 pub fn as_arc(&self) -> &Arc<T> {
393 &self.arc
399 /// receiver), but we have an [`Arc`] instead. Getting an [`ArcBorrow`] is free when optimised.
402 self.arc.as_arc_borrow()
408 Arc::ptr_eq(&this.arc, &other.arc)
420 self.arc.deref()
432 unsafe { T::on_drop_list_arc(&self.arc) };
436 impl<T, const ID: u64> AsRef<Arc<T>> for ListArc<T, ID>
441 fn as_ref(&self) -> &Arc<T> {
461 // INVARIANT: Pin-init initializers can't be used on an existing `Arc`, so this value will
462 // not be constructed in an `Arc` that already has a `ListArc`.