[−][src]Struct elysees::Arc
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]
F: FnOnce(&ArcHandle<T>) -> U,
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]
T: Clone,
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> CloneStableDeref for Arc<T>
[src]
impl<T: Debug> Debug for Arc<T>
[src]
impl<T> Deref for Arc<T>
[src]
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T>
[src]
fn deserialize<D>(deserializer: D) -> Result<Arc<T>, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl<T> Drop for Arc<T>
[src]
impl<T: Eq> Eq for Arc<T>
[src]
impl<T: Hash> Hash for Arc<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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,
T: RefUnwindSafe,
impl<T> Unpin for Arc<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Arc<T> where
T: RefUnwindSafe + UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,