[][src]Struct elysees::Arc

#[repr(transparent)]pub struct Arc<T: ?Sized> { /* fields omitted */ }

An atomically reference counted shared pointer

See the documentation for Arc in the standard library. Unlike the standard library Arc, this Arc holds a pointer to the T instead of to the entire ArcInner. This makes the struct FFI-compatible, and allows a variety of pointer casts, e.g. &[Arc<T>] to &[&T].

  std::sync::Arc<T>     elysees::Arc<T>
  |                     |
  v                     v
 --------------------------------------
| RefCount            | T (data)       | [ArcInner<T>]
 --------------------------------------

This means that this is a direct pointer to its contained data (and can be read from by both C/C++ and Rust)

This is very useful if you have an Arc-containing struct shared between Rust and C/C++, and wish for C/C++ to be able to read the data behind the Arc without incurring an FFI call overhead. This also enables a variety of useful casts, which are provided as safe functions by the library, e.g. &Arc -> &*const T, which can help with safe implementation of complex ByAddress datastructures

Implementations

impl<T> Arc<T>[src]

pub fn new(data: T) -> Self[src]

Construct an Arc<T>

impl<T: ?Sized> Arc<T>[src]

pub fn borrow_arc(&self) -> ArcBorrow<'_, T>[src]

Borrow this Arc<T> as an ArcBorrow<T>

pub fn leak(this: Arc<T>) -> ArcBorrow<'static, T>[src]

Leak this Arc<T>, getting an ArcBorrow<'static, T>

You can call the get method on the returned ArcBorrow to get an &'static T. Note that using this can (obviously) cause memory leaks!

pub fn into_raw(this: Self) -> *const T[src]

Convert the Arc<T> to a raw pointer, suitable for use across FFI

Note: This returns a pointer to the data T, which is offset in the allocation.

pub fn as_ptr(this: &Arc<T>) -> *const T[src]

Get the raw pointer underlying this Arc<T>

pub unsafe fn from_raw(ptr: *const T) -> Arc<T>[src]

Convert the Arc<T> from a raw pointer obtained from into_raw()

Note: This raw pointer will be offset in the allocation and must be preceded by the atomic count.

Safety

This function must be called with a pointer obtained from into_raw(), which is then invalidated.

pub fn is_unique(&self) -> bool[src]

Whether or not the Arc is uniquely owned (is the refcount 1?).

pub fn try_unique(this: Self) -> Result<ArcBox<T>, Arc<T>>[src]

Try to convert this Arc to an ArcBox if it is unique

pub fn count(this: &Arc<T>, ordering: LoadOrdering) -> usize[src]

Get the reference count of this Arc with a given ordering

pub fn ptr_eq(this: &Self, other: &Self) -> bool[src]

Compare two Arcs via pointer equality. Will only return true if they come from the same allocation

impl<T: Clone> Arc<T>[src]

pub fn make_mut(this: &mut Self) -> &mut T[src]

Makes a mutable reference to the ArcHandle, cloning if necessary

This is functionally equivalent to Arc::make_mut from the standard library.

If this ArcHandle is uniquely owned, make_mut() will provide a mutable reference to the contents. If not, make_mut() will create a new ArcHandle 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.

pub fn unique(this: Self) -> ArcBox<T>[src]

Convert this Arc to an ArcBox, cloning the internal data if necessary for uniqueness

Trait Implementations

impl<S: ?Sized + SliceDst> AllocSliceDst<S> for Arc<S>[src]

impl<T: ?Sized> AsRef<*const T> for Arc<T>[src]

impl<T: ?Sized> AsRef<*mut T> for Arc<T>[src]

impl<'a, T: ?Sized> AsRef<Arc<T>> for ArcBorrow<'a, T>[src]

impl<T: ?Sized> AsRef<NonNull<T>> for Arc<T>[src]

impl<T: ?Sized> AsRef<T> for Arc<T>[src]

impl<'a, T: ?Sized> Borrow<Arc<T>> for ArcBorrow<'a, T>[src]

impl<T: ?Sized> Borrow<T> for Arc<T>[src]

impl<T: ?Sized> Clone for Arc<T>[src]

impl<T: ?Sized> CloneStableDeref for Arc<T>[src]

impl<T: ?Sized + Debug> Debug for Arc<T>[src]

impl<T: Default> Default for Arc<T>[src]

impl<T: ?Sized> Deref for Arc<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: ?Sized + Display> Display for Arc<T>[src]

impl<T: ?Sized> Drop for Arc<T>[src]

impl<T: ?Sized + Eq> Eq for Arc<T>[src]

impl<T: ?Sized + Erasable> ErasablePtr for Arc<T>[src]

impl<T> From<T> for Arc<T>[src]

impl<T: ?Sized + Hash> Hash for Arc<T>[src]

impl<T: ?Sized + Ord> Ord for Arc<T>[src]

impl<T: ?Sized + PartialEq> PartialEq<Arc<T>> for Arc<T>[src]

impl<T: ?Sized + PartialOrd> PartialOrd<Arc<T>> for Arc<T>[src]

impl<T: ?Sized> Pointer for Arc<T>[src]

impl<T: ?Sized + Sync + Send> Send for Arc<T>[src]

impl<T: ?Sized> StableDeref for Arc<T>[src]

impl<T: ?Sized + Sync + Send> Sync for Arc<T>[src]

impl<S: ?Sized + SliceDst> TryAllocSliceDst<S> for Arc<S>[src]

impl<T: ?Sized> UnionAlign for Arc<T> where
    Arc<T>: ErasablePtr
[src]

Auto Trait Implementations

impl<T: ?Sized> RefUnwindSafe for Arc<T> where
    T: RefUnwindSafe

impl<T: ?Sized> Unpin for Arc<T> where
    T: Unpin

impl<T: ?Sized> UnwindSafe for Arc<T> where
    T: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erasable for T[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.