pub struct TinyArc<T>(/* private fields */);Expand description
A thread-safe reference-counting tiny pointer. As with all types of this crate, memory is
allocated on the heap. It is equivalent to std::sync::Arc.
use tinypointers::TinyArc;
let x = TinyArc::new(42);
let y = x.clone();
println!("{}", *x); // prints 42
println!("{}", *y); // prints 42
// both x and y point to the same memory locationImplementations§
Source§impl<T> TinyArc<T>
impl<T> TinyArc<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Allocates memory on the heap and then places value into it.
§Example
use tinypointers::TinyArc;
let x = TinyArc::new(42);Sourcepub fn new_cyclic<F>(data_fn: F) -> Self
pub fn new_cyclic<F>(data_fn: F) -> Self
Constructs a new TinyArc<T> while giving you a TinyWeak<T> to the allocation, to allow
you to construct a T which holds a weak pointer to itself.
new_cyclic first allocates the managed allocation for the TinyArc<T>,
then calls your closure, giving it a TinyWeak<T> to this allocation,
and only afterwards completes the construction of the TinyArc<T> by placing
the T returned from your closure into the allocation.
§Panic
Keep in mind that the TinyArc<T> is not fully constructed until TinyArc<T>::new_cyclic
returns. Calling TinyWeak::upgrade will cause a panic.
Sourcepub fn as_ptr(this: &Self) -> *const T
pub fn as_ptr(this: &Self) -> *const T
Returns a raw pointer to the inner value.
The pointer will be valid for as long as there are strong references to this allocation.