pub struct ArcRef<'a, T: Erasable> { /* private fields */ }Expand description
Implementations§
Source§impl<'a, T: Erasable> ArcRef<'a, T>
impl<'a, T: Erasable> ArcRef<'a, T>
Sourcepub fn new(data: T) -> Self
pub fn new(data: T) -> Self
Construct an ArcRef<'a, T>
Sourcepub fn try_unwrap(this: Self) -> Result<T, Self>
pub fn try_unwrap(this: Self) -> Result<T, Self>
Returns the inner value, if the ArcRef is owned and has exactly one strong reference.
Otherwise, an Err is returned with the same ArcRef that was
passed in.
§Examples
use elysees::ArcRef;
let x = ArcRef::new(3);
assert_eq!(ArcRef::try_unwrap(x), Ok(3));
let x = ArcRef::new(4);
let _y = ArcRef::clone(&x);
assert_eq!(*ArcRef::try_unwrap(x).unwrap_err(), 4);Sourcepub fn make_mut(this: &mut Self) -> &mut Twhere
T: Clone,
pub fn make_mut(this: &mut Self) -> &mut Twhere
T: Clone,
Makes a mutable reference to the ArcRef, cloning if necessary.
This is similar to ArcRef::make_mut from the standard library.
If this ArcRef is uniquely owned, make_mut() will provide a mutable
reference to the contents. If not, make_mut() will create a new ArcRef
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 ArcRef is not shared.
Sourcepub fn get_mut(this: &mut Self) -> Option<&mut T>
pub fn get_mut(this: &mut Self) -> Option<&mut T>
Provides mutable access to the contents if the ArcRef is uniquely owned.
Sourcepub fn is_unique(this: &Self) -> bool
pub fn is_unique(this: &Self) -> bool
Whether or not the ArcRef is uniquely owned (is the refcount 1, and is ArcBorrow itself owned?).
Sourcepub fn load_count(this: &Self, order: Ordering) -> usize
pub fn load_count(this: &Self, order: Ordering) -> usize
Gets the number of Arc pointers to this allocation, with a given load ordering
Sourcepub fn try_unique(this: Self) -> Result<ArcBox<T>, Self>
pub fn try_unique(this: Self) -> Result<ArcBox<T>, Self>
Returns an ArcBox if the ArcRef has exactly one strong, owned reference.
Otherwise, an Err is returned with the same ArcRef that was
passed in.
§Examples
use elysees::{ArcRef, ArcBox};
let x = ArcRef::new(3);
assert_eq!(ArcBox::into_inner(ArcRef::try_unique(x).unwrap()), 3);
let x = ArcRef::new(4);
let _y = ArcRef::clone(&x);
assert_eq!(
*ArcRef::try_unique(x).map(ArcBox::into_inner).unwrap_err(),
4,
);Sourcepub fn from_arc(arc: Arc<T>) -> Self
pub fn from_arc(arc: Arc<T>) -> Self
Construct an ArcRef<'a, T> from an Arc<T>
§Examples
use elysees::{Arc, ArcRef};
let x = Arc::new(3);
let y = ArcRef::from_arc(x.clone());
assert_eq!(ArcRef::count(&y), 2);Sourcepub fn from_borrow(arc: ArcBorrow<'a, T>) -> Self
pub fn from_borrow(arc: ArcBorrow<'a, T>) -> Self
Construct an ArcRef<'a, T> from an ArcBorrow<'a, T>
Sourcepub fn try_into_arc(this: Self) -> Result<Arc<T>, ArcBorrow<'a, T>>
pub fn try_into_arc(this: Self) -> Result<Arc<T>, ArcBorrow<'a, T>>
Try to convert this ArcRef<'a, T> into an Arc<T> if owned; otherwise, return it as an ArcBorrow
§Examples
use elysees::ArcRef;
let x = ArcRef::new(3);
assert_eq!(*ArcRef::try_into_arc(x.clone()).unwrap(), 3);Sourcepub fn ptr_eq(this: &Self, other: &Self) -> bool
pub fn ptr_eq(this: &Self, other: &Self) -> bool
Test pointer equality between the two ArcRefs, i.e. they must be the same
allocation
Sourcepub fn leak(this: ArcRef<'_, T>) -> ArcBorrow<'static, T>
pub fn leak(this: ArcRef<'_, T>) -> ArcBorrow<'static, T>
Leak this ArcRef, 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!
Sourcepub fn borrow_arc(this: &'a Self) -> ArcBorrow<'a, T>
pub fn borrow_arc(this: &'a Self) -> ArcBorrow<'a, T>
Borrow this as an ArcBorrow. This does not bump the refcount.
§Examples
use elysees::{ArcBorrow, ArcRef};
let x: ArcRef<u64> = ArcRef::new(3);
assert_eq!(ArcRef::count(&x), 1);
let y: ArcBorrow<u64> = ArcRef::borrow_arc(&x);
assert_eq!(ArcRef::as_ptr(&x), ArcBorrow::into_raw(y));
assert_eq!(ArcRef::count(&x), 1);
assert_eq!(ArcBorrow::count(y), 1);Sourcepub fn into_arc(this: ArcRef<'a, T>) -> Arc<T>
pub fn into_arc(this: ArcRef<'a, T>) -> Arc<T>
Get this as an Arc, bumping the refcount if necessary.
§Examples
use elysees::{Arc, ArcRef};
let x = ArcRef::new(3);
let y = ArcRef::into_borrow(&x);
assert_eq!(ArcRef::as_ptr(&x), ArcRef::as_ptr(&y));
assert_eq!(ArcRef::count(&x), 1);
assert_eq!(ArcRef::count(&y), 1);
let z = ArcRef::into_arc(y);
assert_eq!(ArcRef::as_ptr(&x), Arc::as_ptr(&z));
assert_eq!(ArcRef::count(&x), 2);
assert_eq!(Arc::count(&z), 2);
let w = ArcRef::into_arc(x);
assert_eq!(Arc::count(&w), 2);
assert_eq!(Arc::count(&z), 2);Sourcepub fn into_owned(this: Self) -> ArcRef<'static, T>
pub fn into_owned(this: Self) -> ArcRef<'static, T>
Get this as an owned ArcRef, with the 'static lifetime
§Examples
use elysees::ArcRef;
let x = ArcRef::new(7);
assert_eq!(ArcRef::count(&x), 1);
let y = ArcRef::into_borrow(&x);
assert_eq!(ArcRef::count(&x), 1);
assert_eq!(ArcRef::count(&y), 1);
let z = ArcRef::into_owned(y);
assert_eq!(ArcRef::as_ptr(&x), ArcRef::as_ptr(&z));
assert_eq!(ArcRef::count(&x), 2);
assert_eq!(ArcRef::count(&z), 2);Sourcepub fn into_borrow(this: &'a ArcRef<'a, T>) -> ArcRef<'a, T>
pub fn into_borrow(this: &'a ArcRef<'a, T>) -> ArcRef<'a, T>
Borrow this as an ArcRef. This does not bump the refcount.
§Examples
use elysees::ArcRef;
let x = ArcRef::new(8);
assert_eq!(ArcRef::count(&x), 1);
let y = ArcRef::into_borrow(&x);
assert_eq!(ArcRef::as_ptr(&x), ArcRef::as_ptr(&y));
assert_eq!(ArcRef::count(&x), 1);
assert_eq!(ArcRef::count(&y), 1);Sourcepub fn clone_into_owned(this: &Self) -> ArcRef<'static, T>
pub fn clone_into_owned(this: &Self) -> ArcRef<'static, T>
Clone this into an owned ArcRef, with the 'static lifetime
§Examples
use elysees::ArcRef;
let x = ArcRef::new(7);
assert_eq!(ArcRef::count(&x), 1);
let y = ArcRef::into_borrow(&x);
assert_eq!(ArcRef::count(&x), 1);
assert_eq!(ArcRef::count(&y), 1);
let z = ArcRef::clone_into_owned(&y);
assert_eq!(ArcRef::as_ptr(&x), ArcRef::as_ptr(&z));
assert_eq!(ArcRef::count(&x), 2);
assert_eq!(ArcRef::count(&y), 2);
assert_eq!(ArcRef::count(&z), 2);Sourcepub fn into_raw(this: Self) -> *const T
pub fn into_raw(this: Self) -> *const T
Get the internal pointer of an ArcBorrow. This does not bump the refcount.
§Examples
use elysees::{Arc, ArcRef};
let x = ArcRef::new(7);
assert_eq!(ArcRef::count(&x), 1);
let x_ = x.clone();
assert_eq!(ArcRef::count(&x), 2);
let p = ArcRef::into_raw(x_);
assert_eq!(ArcRef::count(&x), 2);
assert_eq!(ArcRef::as_ptr(&x), p);
let y = unsafe { Arc::from_raw(p) };
assert_eq!(ArcRef::as_ptr(&x), Arc::as_ptr(&y));
assert_eq!(ArcRef::count(&x), 2);
std::mem::drop(y);
assert_eq!(ArcRef::count(&x), 1);Trait Implementations§
Source§impl<'a, 'de, T: Deserialize<'de>> Deserialize<'de> for ArcRef<'a, T>
impl<'a, 'de, T: Deserialize<'de>> Deserialize<'de> for ArcRef<'a, T>
Source§fn deserialize<D>(deserializer: D) -> Result<ArcRef<'a, T>, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<ArcRef<'a, T>, D::Error>where
D: Deserializer<'de>,
Source§impl<'a, T: Erasable + Ord> Ord for ArcRef<'a, T>
impl<'a, T: Erasable + Ord> Ord for ArcRef<'a, T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, 'b, T: Erasable, U: Erasable + PartialEq<T>> PartialEq<ArcRef<'a, T>> for ArcRef<'b, U>
impl<'a, 'b, T: Erasable, U: Erasable + PartialEq<T>> PartialEq<ArcRef<'a, T>> for ArcRef<'b, U>
Source§impl<'a, 'b, T: Erasable, U: Erasable + PartialOrd<T>> PartialOrd<ArcRef<'a, T>> for ArcRef<'b, U>
impl<'a, 'b, T: Erasable, U: Erasable + PartialOrd<T>> PartialOrd<ArcRef<'a, T>> for ArcRef<'b, U>
impl<'a, T: Erasable> CloneStableDeref for ArcRef<'a, T>
impl<'a, T: Erasable + Eq> Eq for ArcRef<'a, T>
impl<'a, T: Erasable + Sync + Send> Send for ArcRef<'a, T>
impl<'a, T: Erasable> StableDeref for ArcRef<'a, T>
impl<'a, T: Erasable + Sync + Send> Sync for ArcRef<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for ArcRef<'a, T>
impl<'a, T> RefUnwindSafe for ArcRef<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Unpin for ArcRef<'a, T>
impl<'a, T> UnwindSafe for ArcRef<'a, T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.