[][src]Struct elysees::Arc

#[repr(transparent)]pub struct Arc<T> { /* 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].

 ArcHandle<T>           Arc<T>
 std::sync::Arc<T>      ArcBorrow<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++ and Rust), but we can also convert it to an ArcHandle<T> by removing the offset.

This is very useful if you have an Arc-containing struct shared between Rust and C++, and wish for C++ to be able to read the data behind the Arc without incurring an FFI call overhead.

Implementations

impl<T> Arc<T>[src]

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

Construct an Arc<T>

pub fn with_handle<F, U>(&self, f: F) -> U where
    F: FnOnce(&ArcHandle<T>) -> U, 
[src]

Temporarily converts |self| into a bonafide ArcHandle and exposes it to the provided callback. The refcount is not modified.

pub fn make_mut(&mut self) -> &mut T where
    T: Clone
[src]

Makes a mutable reference to the Arc, 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 clone_handle(&self) -> ArcHandle<T>[src]

Clone this Arc as an ArcHandle

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

Produce a pointer to the data that can be converted back to an Arc<T>. 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.

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

Borrow this Arc as an ArcBorrow

pub fn get_count(&self, ordering: Ordering) -> usize[src]

Get the reference count of this Arc with a given memory ordering

Trait Implementations

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

impl<'a, T> AsRef<T> for Arc<T>[src]

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

impl<'a, T> Borrow<T> for Arc<T>[src]

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

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

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

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

type Target = T

The resulting type after dereferencing.

impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T>[src]

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

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

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

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

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

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

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

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

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

Auto Trait Implementations

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

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

impl<T> 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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[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, 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.