Struct Agc

Source
pub struct Agc<T: Trace + 'static> { /* private fields */ }
Available on crate feature sync only.
Expand description

A cycle-collected reference-counted smart pointer which may be shared across threads and supports concurrent collection.

Agc<T> provides shared ownership of a value of type T, allocated on the heap. Cloning it will produce a new Agc instance which points to the same allocation as the original Agc.

Unlike std::sync::Arc, Agc pointers may refer to each other in a way that creates cycles arbitrarily without causing leaks, provided that the program calls collect to collect those cycles.

  • In most cases you must call collect to reclaim memory for dropped Agcs even if they are acyclical.
  • You may call collect from any thread to collect cycles. The implementation of collect is intended to provide very low pause times for concurrently running threads, although it will block the thread which actually invokes collect until the collection is complete.
    • While the exact details are subject to change, the current implementation will block access to Agcs data for as long as it takes to update its metadata, and will only do so if that Agc is a candidate for collection.

Implementations§

Source§

impl<T> Agc<T>
where T: Trace + 'static,

Source

pub fn new(data: T) -> Self

Construct a new Agc containing data which will be automatically cleaned up with it is no longer reachable, even in the presence of cyclical references.

Source§

impl<T> Agc<T>
where T: Trace + 'static,

Source

pub fn strong_count(this: &Self) -> usize

Retrieve the current number of strong references outstanding.

Source

pub fn read(&self) -> Ref<'_, T>

Blocks the thread until it can acquire a non-exclusive reference into this Agc.

The returned object is an RAII guard which releases a shared lock. Multiple references may be taken out at the same time.

§Deadlocks

May deadlock if the value is Dead. This should not occur under normal circumstances and likely indicates a bug in a Trace implementation.

§Panics

Panics if the value is Dead. This should not occur under normal circumstances and likely indicates a bug in a Trace implementation.

Source

pub fn try_borrow(&self) -> Option<Ref<'_, T>>

Try to get a non-exclusive reference into this Agc. This will not block the calling thread. This may fail if the object is being concurrently traced by the collector.

Returns None if the pointer is dead or exclusively referenced.

Source

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

Returns true if both this & other point to the same allocation.

Trait Implementations§

Source§

impl<T> Clone for Agc<T>
where T: Trace + 'static,

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Agc<T>
where T: Trace + 'static,

Source§

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

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

impl<T> Drop for Agc<T>
where T: Trace + 'static,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Ord for Agc<T>
where T: Ord + Trace + 'static,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq for Agc<T>
where T: PartialEq + Trace + 'static,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for Agc<T>
where T: PartialOrd + Trace + 'static,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Trace for Agc<T>
where T: Trace + 'static,

Source§

fn visit_children(&self, visitor: &mut GcVisitor<'_>)

Visit the children of this type. The implementation should call visit_children on each owned value which implements Trace.
Source§

impl<T> Eq for Agc<T>
where T: Eq + Trace + 'static,

Auto Trait Implementations§

§

impl<T> Freeze for Agc<T>

§

impl<T> !RefUnwindSafe for Agc<T>

§

impl<T> Send for Agc<T>

§

impl<T> Sync for Agc<T>

§

impl<T> Unpin for Agc<T>

§

impl<T> !UnwindSafe for Agc<T>

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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<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, 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.