Struct elysees::ArcRef [−][src]
#[repr(transparent)]pub struct ArcRef<'a, T: Erasable> { /* fields omitted */ }
Expand description
Implementations
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);
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.
Provides mutable access to the contents if the ArcRef
is uniquely owned.
Whether or not the ArcRef
is uniquely owned (is the refcount 1, and is ArcBorrow
itself owned?).
Gets the number of Arc
pointers to this allocation, with a given load ordering
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,
);
Construct an ArcRef<'a, T>
from an 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);
Test pointer equality between the two ArcRef
s, i.e. they must be the same
allocation
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);
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);
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);
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);
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
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>,
Deserialize this value from the given Serde deserializer. Read more
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>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for ArcRef<'a, T> where
T: RefUnwindSafe,
impl<'a, T> UnwindSafe for ArcRef<'a, T> where
T: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more