TinyArc

Struct TinyArc 

Source
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 location

Implementations§

Source§

impl<T> TinyArc<T>

Source

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);
Source

pub fn new_cyclic<F>(data_fn: F) -> Self
where F: FnOnce(TinyWeak<T>) -> T,

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.

Source

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.

Source

pub fn ptr_eq(this: &Self, other: &Self) -> bool

Checks whether the two TinyArcs point to the same allocation.

Source

pub fn downgrade(this: &Self) -> TinyWeak<T>

Creates a TinyWeak pointer to this allocation.

Weak references do not keep the allocation alive, and cannot access the inner value.

Trait Implementations§

Source§

impl<T> Clone for TinyArc<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for TinyArc<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for TinyArc<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: Display> Display for TinyArc<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for TinyArc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Hash> Hash for TinyArc<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Send + Sync> Send for TinyArc<T>

Source§

impl<T: Send + Sync> Sync for TinyArc<T>

Auto Trait Implementations§

§

impl<T> Freeze for TinyArc<T>

§

impl<T> RefUnwindSafe for TinyArc<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for TinyArc<T>

§

impl<T> UnwindSafe for TinyArc<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.